【发布时间】:2014-10-03 13:55:02
【问题描述】:
我刚刚开始学习 iOS 开发。我正在做“Start Developing iOS Apps Today”教程,我被困在“添加数据”部分。
在将表格视图设置为使用“动态原型”并将标识符设置为“ListPrototypeCell”后,我添加了“cellForRowAtIndexPath”方法,但它因以下错误而崩溃:
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle>(未加载)
2014-08-10 13:35:50.519 ToDoList[8954:60b] *** 断言失败 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439
2014-08-10 13:35:50.523 ToDoList[8954:60b] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法使具有标识符 ListPrototypeCell 的单元格出列 - 必须注册一个 nib 或一个标识符的类或连接故事板中的原型单元'
。 . . .
libc++abi.dylib:以 NSException 类型的未捕获异常终止
我一直严格按照教程进行操作,但找不到错误。谁能建议我做错了什么?
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListPrototypeCell" forIndexPath:indexPath];
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
return cell;
}
【问题讨论】:
-
您是否将视图控制器设置为放置此代码的类的名称?
-
添加“异常断点”以停止导致此问题的行(应为 dequeueReusableCellWithIdentifier :)。检查您是否在正确的控制器中实现了该方法,并且在 Storyboard 表控制器中具有正确的类。
标签: ios xcode cocoa-touch