在我的故事板中,我有一个UITableViewController
和静态单元格和4个部分。UITableViewController中的第二个tableview
- 第1部分第6行和第1行高度比其他高得多。
- 第2节有1行。
- 第3节有4行。
- 第4节有1行。
在第4节的行,我加入到UITableView
(表2)与动态细胞(无标头,仅1节)。
所以我跟一些帖子,并有下面的一些代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
if tableView == table2 {
return 1
}
return super.numberOfSectionsInTableView(tableView)
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == table2 {
return 4
}
return super.tableView(tableView, numberOfRowsInSection: section)
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if tableView == table2 {
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as! CustomerCellView
cell.setCustomCell()
return cell
}
return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
}
当运行它,它成功生成。默认表显示正确,但表2没有。表2似乎遵循默认表的格式,这样的问题是
table2
也显示相同的标题为默认表的第一头部,即使我没有设置。- 如果我设置的行数大于6,则应用程序在模拟器中崩溃。
- 我把断点设置为
tableView == table2
,编译器进入if语句 table2
委托和数据源连接到UITableViewController本身。
如果有谁知道什么问题,我的代码了,或者有人知道如何添加第二个的tableview在UITableViewController
感谢您的回复。我确实尝试了这一点,但是当我在'UIViewController'中设置'static cells'时,会出现一个红色的错误信息msg:“静态表视图只有在嵌入UITableViewController实例时才有效” – Jimmy
您是否制作了数据源和代理插座? –
并在视图控制器类中添加委托? –