简体   繁体   English

使用TableView向视图控制器添加导航

[英]Adding a Navigation to a View Controller with a TableView

I'm trying to add (or have) a navigation bar (or items) on the top of a View controller and and a tableview right below the navigation bar. 我正在尝试在View控制器的顶部添加(或具有一个)导航栏(或项),并在该导航栏的正下方添加一个tableview。 The problem I'm having is when I set the tableview's datasource to View Controller, my app will crash (setting the tableview's delegate to View controller doesn't). 我遇到的问题是,当我将tableview的数据源设置为View Controller时,我的应用程序将崩溃(没有将tableview的委托设置为View controller)。 For now, the code for the tableview are in the default ViewController.m. 目前,tableview的代码位于默认的ViewController.m中。 Do I have the tableview's code in the right place or did I connect something improperly? 是否在正确的位置放置了tableview的代码,或者连接不正确?

Here's the error that it gives me: 这是它给我的错误:

2013-10-10 15:14:48.442 SomeApp[15058:a0b] -[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450 2013-10-10 15:14:48.450 SomeApp[15058:a0b] *** Terminating app due to uncaught exception >'NSInvalidArgumentException', reason: '-[UIViewController >tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x8d42450' 2013-10-10 15:14:48.442 SomeApp [15058:a0b]-[UIViewController> tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x8d42450 2013-10-10 15:14:48.450 SomeApp [15058:a0b] ** *由于未捕获的异常>'NSInvalidArgumentException'而终止应用程序,原因:'-[UIViewController> tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x8d42450'

当前设置

Make sure your view controller adheres to the proper protocols: 确保您的视图控制器遵守正确的协议:

CustomViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

And add the necessary methods from these protocols to your implementation. 并将这些协议中的必要方法添加到您的实现中。 These are the documentation links for your ease: 这些是为您提供方便的文档链接:

UITableViewDelegate Protocol Reference UITableViewDelegate协议参考

UITableViewDataSource Protocol Reference UITableViewDataSource协议参考

You are missing some methods that are required for your tableview to work, 您缺少工作表视图所需的一些方法,

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

More information on UITableViewDataSource Protocol Reference 有关UITableViewDataSource协议参考的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将带有导航 controller 的 tableView 添加到基于视图的项目中 - iPhone 编程 - Adding tableView with navigation controller to a view-based project - iPhone Programming TableView 被分配给导航控制器而不是视图控制器 - TableView being assigned to navigation controller not view controller 从tableview看到导航控制器之前的视图 - Segue from tableview to view preceded by navigation controller 在导航控制器的导航栏下添加视图 - Adding view beneath navigation bar in navigation controller 在视图控制器子类上添加导航控制器 - Adding navigation controller on a view controller subclass 如何在表格视图单元格上按以向视图控制器显示导航控制器中的文本 - How to press on a tableview cell to present a view controller with the text in navigation controller 带有TableView的导航控制器 - Navigation Controller with TableView 从View控制器导航烘焙时删除tableview单元格 - delete tableview cell when navigation bake from View controller 如何使TableView控制器上的视图覆盖导航栏? - How to make a view on a TableView controller cover the navigation bar? 在视图控制器中添加多个导航控制器? - Adding multiple navigation controllers inside a view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM