[英]Xcode TableView - unrecognized selector sent to instance
I'm trying to learn table views and I've hit a snag. 我正在尝试学习表格视图,但遇到了麻烦。 I have the view delegate and datasource connected correctly in Storyboard, but I get the following runtime error when I get to the section of my app containing the table view.
我已经在Storyboard中正确连接了视图委托和数据源,但是当我到达包含表视图的应用程序部分时,出现以下运行时错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
Here's the chunk from my implementation file 这是我的实现文件中的块
@implementation CraftingViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Detail";
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
That error message is displaying because tableView:numberOfRowsInSection:
is being sent to an object of type UINavigationItem
while it seems like your CraftingViewController
class is probably of type UITableViewController
. 之所以显示该错误消息,是因为
tableView:numberOfRowsInSection:
被发送到UINavigationItem
类型的对象,而您的CraftingViewController
类可能是UITableViewController
类型。 I would make sure that you have connected your delegate to the correct class, because it doesn't seem like CraftingViewController
is connected properly. 我将确保您已将委托连接到正确的类,因为
CraftingViewController
似乎未正确连接。
if the datasource is controller of the nib file. 如果数据源是nib文件的控制器。
please check alloc of this controller use "CraftingViewController" not "UIViewController" 请检查此控制器的分配使用“ CraftingViewController”而不是“ UIViewController”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.