我使用Interface中的原型单元格将一个脚注添加到表视图中:
实例化页脚时,dequeueReusableHeaderFooterViewWithIdentifier()
将返回单元格的nil,但dequeueReusableCellWithIdentifier()
不返回。我在Interface中创建了一个具有正确标识符的页脚视图:
然后实例化页脚:
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let id = "MyFooter"
// this works:
// guard let footerCell = self.todaysChoresTableView.dequeueReusableCellWithIdentifier(id) else {
// return nil
// }
guard let footerCell = self.todaysChoresTableView.dequeueReusableHeaderFooterViewWithIdentifier(id) else {
// this doesn't, always returning nil
return nil
}
}
为什么dequeueReusableHeaderFooterViewWithIdentifier()
总是返回零?
(lldb) po self.tableView.dequeueReusableHeaderFooterViewWithIdentifier(id)
nil
(lldb) po self.tableView.dequeueReusableCellWithIdentifier(id)
▿ Optional(<UITableViewCell: 0x7fa313c835f0; frame = (0 0; 600 44); clipsToBounds = YES; layer = <CALayer: 0x7fa313c73150>>)
- Some : <UITableViewCell: 0x7fa313c835f0; frame = (0 0; 600 44); clipsToBounds = YES; layer = <CALayer: 0x7fa313c73150→
更新:
我也尝试过这样做,虽然现在它不再是nil
了,但它似乎并没有构建一个基于IB设计的视图:
tableView.registerClass(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: id)
let footerView: UITableViewHeaderFooterView? = self.todaysChoresTableView.dequeueReusableHeaderFooterViewWithIdentifier(id)
footerView!.backgroundColor = UIColor.redColor()
return footerView
https://stackoverflow.com/questions/35541788
复制相似问题