Ios 如何制作可展开的侧菜单tableView列表
我试图扩展我的tableView,但是我得到了一个 线程1:信号SIGABRT错误。由于未捕获的异常“NSRangeException”而终止应用程序,原因:'***-[\uu\NSSingleObjectArrayI objectAtIndex:]:索引6超出边界[0..0]' 这是我写的代码Ios 如何制作可展开的侧菜单tableView列表,ios,swift,uitableview,expandablelistview,side-menu,Ios,Swift,Uitableview,Expandablelistview,Side Menu,我试图扩展我的tableView,但是我得到了一个 线程1:信号SIGABRT错误。由于未捕获的异常“NSRangeException”而终止应用程序,原因:'***-[\uu\NSSingleObjectArrayI objectAtIndex:]:索引6超出边界[0..0]' 这是我写的代码 override func viewDidLoad() { super.viewDidLoad() tableViewData = [cellData(opened
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
}
}
如何解决此问题。表视图的内容是静态的。这是有意的吗?代码显然与动态原型相关。请用大写字母命名结构和类,并强制展开表视图单元格。如果代码崩溃,它会暴露出一个设计错误。我认为这是一个设计错误。因为当我尝试创建一个正常大小的tableViewController时,它可以工作。但是当它像这样的时候,它给了我一个错误。侧菜单的教程和可扩展表视图的教程来自两个不同的人。不,我的意思是,如果在
dequeueReusableCell
行中强制展开(而不是保护)单元格,并且代码在这些行中崩溃,那么设计错误就会暴露出来。我将其设置为动态,如果我不希望所有内容都展开,例如,我只希望设置展开,如何调用didSelectRow