【发布时间】:2015-11-05 12:39:22
【问题描述】:
在我的故事板中,我有一个UITableViewController,其中包含 static 单元格和 4 个部分。
- 第 1 部分有 6 行,第 1 行高度比其他部分高得多。
- 第 2 节有 1 行。
- 第 3 节有 4 行。
- 第 4 节,1 行。
在第 4 节的行中,我添加到带有 动态 单元格的 UITableView (table2)(无标题,仅 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)
}
运行它时,它会成功构建。默认表正确显示,但 table2 没有。 table2 似乎遵循默认表的格式,所以问题是
-
table2也显示了和默认表的第一个表头相同的表头,即使我没有设置。 - 如果我将行数设置为大于 6,则应用在模拟器中崩溃。
- 我把断点放在
tableView == table2,编译器确实进入了if语句 -
table2委托和数据源连接到 UITableViewController 本身。
如果有人知道我的代码有什么问题,或者有人知道如何在UITableViewController 中添加第二个表格视图
【问题讨论】:
标签: ios iphone swift uitableview