【发布时间】:2015-02-15 14:54:43
【问题描述】:
我想使用界面生成器为表格视图部分创建自定义标题。我不能使用 titleForHeaderInSection 方法,因为我需要显示两个标签。我使用了以下说明:Customizing Header and Footer of TableView in iOS8,但它不起作用。
到目前为止我做了什么:
- 创建一个继承自 UITableViewCell 的自定义类 CustomTableCell
class CustomTableCell: UITableViewCell {
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var dateDescriptionLabel: UILabel!
}
- 在情节提要中创建动态原型单元
- 添加标识符
- 将标签连接到自定义 UITableViewCell
- 实施
viewForHeaderInSection
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("CustomTableCell") as CustomTableCell
headerCell.backgroundColor = UIColor.cyanColor()
headerCell.dateLabel.text = "Test date"
headerCell.dateDescriptionLabel.text = "Test date description"
return headerCell
}
当我运行应用程序时,该部分出现一秒钟,然后在表格单元格下方移动,我收到错误:没有重复使用表格单元格的索引路径。
这个解决方案有什么问题?我从链接的教程中下载了该项目,它在那里工作。
【问题讨论】:
-
tableView的delegate & datasource你设置了吗?
-
是的,当然。否则标题部分不会在一秒钟内显示
-
可以添加错误的日志吗?
-
015-02-15 17:39:01.791 MyApp[16701:530127] 没有重复使用表格单元格的索引路径 2015-02-15 17:39:01.791 MyApp[16701:530127] 没有索引重用表格单元格的路径
-
看来你在另一个方法调用中做错了,你能把你的项目添加到 gitHub 并分享一个链接吗?生病去吧
标签: ios uitableview swift ios8 uistoryboard