如何制作可扩展的侧菜单表格视图列表

时间:2019-09-05 06:14:17

标签: ios swift uitableview expandablelistview side-menu

我正在尝试扩展tableView,但是我得到了

  

线程1:信号SIGABRT错误。由于未捕获的异常'NSRangeException'而终止应用程序,原因:'***-[__ NSSingleObjectArrayI objectAtIndex:]:索引6超出范围[0 .. 0]'

这是我编写的代码。

    override func viewDidLoad() {
        super.viewDidLoad() 

     tableViewData = [cellData(opened: false, title: "Name", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "Type", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "Color", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "Plate", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "Setting", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "About", sectionData: ["Cell 1", "Cell 2", "Cell 3"]),
                         cellData(opened: false, title: "Logout", sectionData: ["Cell 1", "Cell 2", "Cell 3"])]
    }

    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
        } else {
            return 1
    }
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else { return UITableViewCell()}
            cell.textLabel?.text = tableViewData[indexPath.section].title
            return cell
        } else {
            guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else { return UITableViewCell()}
            cell.textLabel?.text = tableViewData[indexPath.section].sectionData[indexPath.row]
            return cell
        }
    }

enter image description here

我该如何解决这个问题。

0 个答案:

没有答案