[英]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.