由于单元标识符导致UITableViewController崩溃

时间:2014-04-15 00:03:46

标签: ios uitableview uistoryboard

我正在尝试加载UITableViewController但是我一直收到此错误并且我的应用程序崩溃了。

*断言失败 - [UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/ SourceCache / UIKit_Sim / UIKit-2935.137 / UITableView.m:5439 2014-04-15 00:40:55.244 TradingGame [966:60b] * 由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符单元格对单元格出列 - 必须注册一个笔尖或一个类标识符或连接故事板'

中的原型单元格

继承我的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

if (cell) {
    // will eventually put labels etc here.
}
return cell;

}

Image showing that i set the identifier

这是我调用我的UITableViewController推送到屏幕的地方:

    if (indexPath.row == 1) {
    Foo *foo = [[Foo alloc] init];
    [self.navigationController pushViewController:foo animated:YES];
}

1 个答案:

答案 0 :(得分:3)

问题解决了。感谢@ Paulw11指出了实例化表视图。 那些对我有类似问题的人会对tableview的实例化进行以下更改: 先试试这个:

Foo *foo = [[Foo alloc] init];
[self.navigationController pushViewController:foo animated:YES];

如果这不起作用,您可能会遇到类似的问题,因此请使用此代码:

Foo *foo = [self.storyboard instantiateViewControllerWithIdentifier:@"Foo"];
[self.navigationController pushViewController:foo animated:YES];

在适用的情况下替换课程" Foo"应该等于您尝试实例化的视图控制器的Storyboard ID。