我认为我错过了一些简单的东西,但我无法弄清楚它到底是什么。
我正在尝试使用 UITabViewController
设置一个应用程序,其中一个选项卡将具有 UITableView 和 UISearchBar(但没有导航 Controller )。我使用界面生成器中的所有选项卡设置了 UITabViewController
,并且 View 位于它们自己的 xib 文件中。带有 UITableView
的选项卡的 xib 文件设置并连接如下。
浏览器中的内容: 文件的所有者(Class 是我的自定义类,它是 UITableViewController 的子级) View -> View
View (class UIView, reference view -> File's owner) contains:
UITableView (if i try and set references to the data source / delegate, the app breaks)
UISearchBar (unconfigured at the moment)
此设置显示所有项目并且不会锁定,但当我尝试使用 UITableView 加载选项卡时,我无法分配数据源而不崩溃。我应该怎么做才能将数据放入此表中,无论是在 IB 中还是在代码中?我的想法如下:
- 实现自定义 UITableView 类,连接到 IB 中的 TableView 或 Xcode 中的自定义 tableviewcontroller。
- 将头或笔记本电脑靠在墙上,直至其正常工作。
更新: 这是当我连接 Tableview 的数据源并委托(delegate)给文件所有者(谁的类是我的自定义 tableviewcontroller)时模拟器推送到控制台的错误。
2/14/09 6:59:12 PM TabBarWillbeRight[33172] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x523760
最佳答案
我遇到了类似的问题,并带有相同的错误消息。简单的解决方案是在 IB 中单击 TabBarController 中的 View (灰色矩形,上面写着“ View 加载自..”),并将元素的类更改为我的 TableViewController 的类名。
关于iPhone:TabView + TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/550026/