我正在XIB
文件中构建我的部分标题视图:
这是一个 XIB 文件,由一个UISearchBarController
内部UIView
我viewDidLoad
在 tableViewController 中注册它:
tableView.register(UINib(nibName: "MessagesSH", bundle: nil), forHeaderFooterViewReuseIdentifier: "MessagesSH")
我把它称为viewForHeaderInSection:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
// Below is the where the app crashes
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "MessagesSH") as? MessagesSH
return headerView
}
当我运行该应用程序时,它崩溃了:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (MessagesSH) - nib must contain exactly one top level object which must be a UITableViewHeaderFooterView instance'