Xcode iOS - Assertion Error

I am just starting to learn iOS development. I'm doing " Start iOS App Development Today " and I'm stuck with the Add Data section.

After setting the Table view to use "Dynamic Prototypes" and setting the id to "ListPrototypeCell" I added the cellForRowAtIndexPath method, but its crashing with these errors:

Applications / Xcode.app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDK / iPhoneSimulator7.1.sdk / System / Library / AccessibilityBundles / CertUIFramework.axbundle> (not loaded)

2014-08-10 13: 35: 50.519 ToDoList [8954: 60b] *** Assertion failed in - [UITableView dequeueReusableCellWithIdentifier: forIndexPath:], / SourceCache / UIKit_Sim / UIKit-2935.137 / UITableView.m: 5439

2014-08-10 13: 35: 50.523 ToDoList [8954: 60b] *** Application terminated due to uncaught exception "NSInternalInconsistencyException", reason: "Failed to delete cell with identifier ListPrototypeCell - you need to register a thread or class for an identifier or connect cell prototype in storyboard

. ,,.

libc ++ abi.dylib: exit with an uncaught exception of type NSException

I've followed the tutorial closely and I can't seem to find the error. Can anyone suggest what I am doing wrong?

enter image description hereenter image description here Code:

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

      

+3


source to share


1 answer


Using:

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

      

For storyboarding whatever you want. Also, if necessary, do the following:



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

      

Edit: if you want to continue using instead dequeueReusableCellWithIdentifier:forIndexPath:

, then in your controller initialization you should use registerClass:forCellReuseIdentifier:

as in the docs unless you are using a storyboard. Also, the (cell == nil) part has become unnecessary in recent versions of Xcode.

+4


source







All Articles