XCode iOS - 断言失败

时间:2014-08-10 17:47:38

标签: ios xcode cocoa-touch

我刚刚开始学习iOS开发。我正在做“Start Developing iOS Apps Today”教程,我坚持使用“添加数据”部分。

在将Table视图设置为使用'Dynamic Prototypes'并将标识符设置为'ListPrototypeCell'之后,我添加了方法'cellForRowAtIndexPath',但是它已经崩溃了这些错误:

  

应用程序/ Xcode.app /内容/开发商/平台/ iPhoneSimulator.platform /开发商/软件开发工具包/ iPhoneSimulator7.1.sdk /系统/库/ 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对单元格出列 - 必须注册一个笔尖或一个标识符的类或连接故事板'

中的原型单元格      

。   。   。   

     

libc ++ abi.dylib:以NSException类型的未捕获异常终止

我一直在完全按照教程,我找不到错误。任何人都可以建议我做错了吗?

enter image description here enter image description here 代码:

- (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;
}

1 个答案:

答案 0 :(得分:4)

使用:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ListPrototypeCell"];

对于你想要的故事板。 如有必要,请跟进:

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

修改:如果您希望继续使用dequeueReusableCellWithIdentifier:forIndexPath:,那么在您的控制器初始化中,如果您没有使用故事板,则应根据文档使用registerClass:forCellReuseIdentifier:。在最新的Xcode版本中,(cell == nil)部分也变得不必要了。

相关问题