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

时间:2013-10-10 21:26:41

标签: ios objective-c uitableview xcode5 uinavigationitem

我正在尝试在视图控制器顶部添加(或拥有)导航栏(或项目),并在导航栏正下方添加一个桌面视图。我遇到的问题是当我将tableview的数据源设置为View Controller时,我的应用程序将崩溃(将tableview的委托设置为View控制器不会)。目前,tableview的代码位于默认的ViewController.m中。我是否将tableview的代码放在正确的位置,或者我是否连接了不正确的内容?

这是它给我的错误:

  

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'

Current setup

2 个答案:

答案 0 :(得分:1)

确保您的视图控制器符合正确的协议:

CustomViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

并将这些协议中的必要方法添加到您的实现中。这些是您方便的文档链接:

UITableViewDelegate Protocol Reference

UITableViewDataSource Protocol Reference

答案 1 :(得分:0)

您缺少桌面视图工作所需的一些方法,

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

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

有关UITableViewDataSource Protocol Reference

的更多信息
相关问题