【问题标题】:Can't bind UISearchBar in Interface Builder无法在 Interface Builder 中绑定 UISearchBar
【发布时间】:2011-10-27 16:23:58
【问题描述】:

我在 Xcode 中启动了一个 TabBar 应用程序。然后我添加了一个称为搜索的选项卡。然后我用名为 SearchController 的 XIB 文件创建了一个 UITableViewController。在 MainWindows.xib 中,我将第三个选项卡链接到 XIB 文件“SearchController”。

我为 UISearchBar 创建了 IBOutlet。在 Interface Builder 中,我添加了 UISearchBar,当我运行项目时一切正常,但是当我尝试将 UISearchBar 绑定到我的 IBOutlet 时,当我单击“搜索”选项卡时它引发了异常:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewController 0x4e3ee80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key searchBar.'
*** Call stack at first throw:"

【问题讨论】:

    标签: iphone objective-c uitableview uisearchbar xib


    【解决方案1】:

    您是否为UISearchBar 创建了IBOutlet 作为属性?在你的.h 文件中有这样的东西:

    @property (strong,nonatomic) IBOutlet UISearchBar *searchBar;
    

    如果是这样,您忘记在 .m 文件中合成属性:

    @synthesize searchBar = _searchBar;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-21
      • 1970-01-01
      • 2011-11-28
      • 2017-05-20
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多