'无法识别的选择器'尝试在导航表视图中显示配方列表时收到

时间:2016-05-24 14:38:45

标签: ios

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:      (NSInteger)section
{
return [recieps count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.textLabel.text = [recieps objectAtIndex:indexPath.row];
return cell;
}

我想在导航表视图中显示食谱列表,但我收到unrecognized selector sent to instance 0x7f8c61709f80

等错误

2 个答案:

答案 0 :(得分:1)

iOS中的“无法识别的选择器”意味着您正在尝试调用您要求的对象无法理解的方法。

你说[someObject doThisMethod],但someObject不知道你在说什么。

该对象的方法不存在&需要添加,或者您的故事板连接或类有问题。

错误告诉您问题是什么&其中:

 -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fec31c38af0

这告诉您tableView实例(在内存地址0x7fec31c38af0)收到消息numberOfRowsInSection:,但它不知道该怎么做。

如果您正在为UITableView使用自定义类,请确保在故事板中正确设置它。另外,请确保您已正确连接UITableViewDelegateUITableViewDataSource

由于它无法识别这种必需的UITableViewDataSource协议方法,因此您可能忘记添加或挂接它。仔细检查您的故事板连接,并确保您的UITableView类实际符合UITableViewDataSource协议。

另外,它是“食谱”......你在几个地方拼错了它“recieps”......

答案 1 :(得分:-1)

在上面的代码中,没有调用section方法。请添加以下代码行

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 返回1; }

注意: 然后你要调用一些控制器中不存在的方法。这就是为什么你得到了无法识别的选择器'控制台上的错误消息。试着找出方法并再次检查。