我想加入我的
UITableView
一些自定义的节标题,我在网上搜索过,看到许多人正在创建
UITableViewCell
UITableViewHeaderFooterView
所以我试着自己做,我创建了一个xib文件和一个
UITableViewHeaderFooterView
SelectedProductsSectionHeader
.
以下是我连接插座的方法
下面是UITableViewController端的相关代码-
override func viewDidLoad() {
super.viewDidLoad()
let selectedProductsSectionHeaderNib = UINib(nibName: "SelectedProductsSectionHeader", bundle: nil)
tableView.register(selectedProductsSectionHeaderNib, forHeaderFooterViewReuseIdentifier: "selectedProductsHeader")
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == SectionIndex.selectedProducts{
let selectedProductsHeaderCell = tableView.dequeueReusableHeaderFooterView(withIdentifier: "selectedProductsHeader") // throws error
guard let selectedProductsHeader = selectedProductsHeaderCell as? SelectedProductsSectionHeader else { return nil }
return selectedProductsHeader
}
return nil
}
运行时错误:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:[设置值:forUndefinedKey:]:此类不符合密钥标签的密钥值编码
我的问题是为什么第一种方法不起作用?我是不是应该用文件的所有者?如果没有-我该怎么用?