0

我正在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'

4

1 回答 1

0

就我而言,我发现 Xib 文件中不能有任何类型的控制器(即UIViewController,UISearchBarController等)。我不得不使用故事板而不是 XIB。

于 2017-04-10T20:43:54.503 回答