ios - 使用 TableView 添加导航到 View Controller

标签 ios objective-c uitableview xcode5 uinavigationitem

我正在尝试在 View Controller 的顶部添加(或具有)导航栏(或项目),并在导航栏正下方添加一个表格 View 。我遇到的问题是当我将 tableview 的数据源设置为 View Controller 时,我的应用程序将崩溃(将 tableview 的委托(delegate)设置为 View controller 不会)。现在,tableview 的代码在默认的 ViewController.m 中。我是否在正确的位置放置了 tableview 的代码,或者我是否连接不正确?

这是它给我的错误:

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'

Current setup

最佳答案

确保您的 View Controller 遵守正确的协议(protocol):

CustomViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

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

UITableViewDelegate Protocol Reference

UITableViewDataSource Protocol Reference

关于ios - 使用 TableView 添加导航到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306534/

相关文章:

ios - 由于我的 'NSInvalidArgumentException' 中的未捕获异常 "game"而终止应用程序

ios - 当用户点击图表时添加点 - 'LineChartView' (iOS-Charts)

objective-c - 从现有 Controller 创建 UIPopoverController

ios - View 中的 UIPanGestureRecognizer 速度可能为零?

ios - 使用 UIRefreshControl 并设置 contentInset 时表格 View 内容跳转

ios - 更改自定义 tableViewCell 的背景颜色

iphone - 如何在UITableView中将 "Dock"一个UIToolbar放到屏幕底部?

objective-c - 检查数组中是否存在对象的问题?

objective-c - 如何实现 "Refresh"和 "Reload"表(代码重构)

UITableView 多对勾选择