【问题标题】:Xcode 8: Adding UISearchBarController to UITableViewHeaderFooterView crash: nib must contain exactly one top level objectXcode 8:将 UISearchBarController 添加到 UITableViewHeaderFooterView 崩溃:nib 必须恰好包含一个顶级对象
【发布时间】:2017-03-08 14:53:31
【问题描述】:

我正在 XIB 文件中构建我的部分标题视图:

这是一个 XIB 文件,由 UISearchBarControllerUIView 组成

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

【问题讨论】:

    标签: ios xcode uitableview uisearchdisplaycontroller uitableviewsectionheader


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 2013-12-24
      • 2013-09-09
      • 2012-04-17
      • 2017-05-02
      • 2020-01-23
      • 2020-04-07
      • 2023-03-14
      • 2020-07-24
      相关资源
      最近更新 更多