【发布时间】:2013-04-06 09:01:17
【问题描述】:
我是 Objective C 和 iOS 的新手。我在情节提要的视图控制器上嵌入了一个导航控制器。然后我在情节提要中添加了另一个视图控制器,它是根视图控制器。它有一个按钮连接到另一个视图控制器,该控制器添加了一个表视图。当我运行构建时,我收到以下异常:'NSInvalidArgumentException' 原因:'-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x686d160'。这是实现文件中的代码(仅相关方法)如果我需要提供更多代码,请告诉我:
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [contacts 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 = [contacts objectAtIndex:indexPath.row];
return cell;
}
【问题讨论】:
-
联系人数组有值吗?
-
它清楚地表明您的
contacts数组有一些无效值,例如空或空。因此,请确保它不为 null 并且其中包含一些值。 -
您可以向 nil 对象发送消息,但不能向已释放对象发送消息。
-
我不知道怎么可能得到这个错误。这是说你的 UIViewController 不理解表视图委托消息 tableView:numberOfRowsInSection:。我认为您应该显示此控制器中的所有代码,包括 .h 文件中的任何属性声明。
标签: ios objective-c xcode4.3 uistoryboard