Uitableview 在单元格内展开表视图单元格

Uitableview 在单元格内展开表视图单元格,uitableview,Uitableview,我试图在viewCell内部创建一个可扩展的表视图 import UIKit class TableSupportVC: UITableViewController { let interface: TableSupportView = { let interface = TableSupportView(frame: CGRect.zero) interface.translatesAutoresizingMaskIntoConstra

我试图在viewCell内部创建一个可扩展的表视图

import UIKit

class TableSupportVC: UITableViewController {


    let interface: TableSupportView = {
           let interface = TableSupportView(frame: CGRect.zero)
           interface.translatesAutoresizingMaskIntoConstraints = false
           return interface
       }()


    struct cellData {
        var opened = Bool()
        var title = String()
        var sectionData = [String]()
    }

    struct dataInside {
        var opened = Bool()
        var title = String()
        var info = [String]()
    }

    var tableViewData = [cellData]()
    var tableViewDataInside = [dataInside]()

    override func viewDidLoad() {
        super.viewDidLoad()

        //register tables
        tableView.register(TableSupportCell.self, forCellReuseIdentifier: menuCellIdita)
        tableView.register(TableSupportSubtitleCell.self, forCellReuseIdentifier: menuCellda)

        // Heres my data for cells 
        tableViewData = [cellData(opened: false, title: "1", sectionData: ["1.1", "1.2","1.3","1.4"]),
            cellData(opened: false, title: "2", sectionData: ["2.1", "2.2", "2.3"])
        ]



        tableViewDataInside = [dataInside(opened: false, title: "1.1.1", info: ["1.1.1"])]


        setThemeNavigationBar()
                // Size Scrollview
        interface.scrollView.contentSize = CGSize(width: wScreen, height: hScreen * 1.40)

                initComponents()



    }



    func setThemeNavigationBar() {

        let navigationBarAppearace = UINavigationBar.appearance()
        navigationBarAppearace.tintColor = blueBlumon
        navigationBarAppearace.barTintColor = blueBlumon
        navigationController?.navigationBar.barTintColor = blueBlumon
        navigationController?.navigationBar.barStyle = .blackOpaque
        navigationController?.navigationBar.isTranslucent = false

    }


    private func initComponents() {

        setNavItems()
        setSubviews()
        setAutolayout()


    }


    private func setSubviews() {
        view.backgroundColor = UIColor.white
        view.addSubview(interface)
    }



    private func setNavItems() {

        let backIcon = UIImage(named: "whiteArrow")
        let backItem = UIBarButtonItem(image: backIcon?.withRenderingMode(.alwaysTemplate), style: UIBarButtonItem.Style.plain, target: self, action: #selector(backPressed))
        backItem.tintColor = UIColor.white
        navigationItem.leftBarButtonItem = backItem

        let logoIcon = UIImage(named: "itemLogoBlue")
        let logoItem = UIBarButtonItem(image: logoIcon?.withRenderingMode(.alwaysOriginal), style: UIBarButtonItem.Style.plain, target: nil, action: nil)
        navigationItem.rightBarButtonItem = logoItem

    }

    // Método para definir el autolayout de los componentes de la vista principal del controlador
    private func setAutolayout() {

        NSLayoutConstraint.activate([
            interface.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            interface.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            interface.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
            interface.leadingAnchor.constraint(equalTo: view.leadingAnchor)
            ])

    }

    // Método de selector backPressed
    @objc private func backPressed() {
        self.navigationController?.popViewController(animated: true)
        dismiss(animated: true, completion: nil)
    }
    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return tableViewData.count
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


        if tableViewData[section].opened == true{
            return tableViewData[section].sectionData.count + 1
        }

             **//INDEX OUT OF RANGE HERE**
            if tableViewDataInside[section].opened == true{
                return tableViewDataInside[section].info.count + 1
            }
        else {
            return 1
        }
        }



    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        if indexPath.row == 0{
            let cell = tableView.dequeueReusableCell(withIdentifier: menuCellIdita, for: indexPath) as! TableSupportCell
            cell.optionTitle.text = tableViewData[indexPath.section].title

            return cell

        }
        if indexPath.row == 2 && tableViewData[indexPath.section].title == "1.2"{
                let cell = tableView.dequeueReusableCell(withIdentifier: menuCellda, for: indexPath) as! TableSupportSubtitleCell
                cell.title.text = tableViewDataInside[indexPath.section].title
                //cell.subtitle.text = tableViewDataInside[indexPath.section].info
                       return cell
            }

        else {

            let cell = tableView.dequeueReusableCell(withIdentifier: menuCellIdita, for: indexPath) as! TableSupportCell
            cell.optionTitle.text = tableViewData[indexPath.section].sectionData[indexPath.row - 1]

            return cell
        }
    }







    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("el indexpath es: \(indexPath.row)")
        if indexPath.row == 0 {
            if tableViewData[indexPath.section].opened == true{
                tableViewData[indexPath.section].opened = false
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)


            }

            else{
                tableViewData[indexPath.section].opened = true
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)

            }


        }

        if indexPath.row == 2 && tableViewData[indexPath.section].title == "1.2"{
            if tableViewDataInside[indexPath.section].opened == true{
                tableViewDataInside[indexPath.section].opened = false
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)


            }

            else{
                tableViewDataInside[indexPath.section].opened = true
                let sections = IndexSet.init(integer: indexPath.section)
                tableView.reloadSections(sections, with: .none)

            }


        }
    }

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 80
    }



}
正如您所看到的,每次用户选择某些单元格时,它都会激活

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0 {
如果用户按第0行,将激活该代码

同样的情况

重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{

但是当我试着设置

重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{

并将其运行崩溃指数超出范围

主要的问题是不能像我正在做的扩展那样在另一个单元格中归档设置信息,我想再次归档 tableViewDataInside这是我的信息,但我可以让它工作