3
votes

I’m just starting out to learn iOS development. I’m doing the “Start Developing iOS Apps Today” tutorial and I’m stuck on the section “Add Data”.

After setting the Table view to use ‘Dynamic Prototypes’, and setting the identifier to ‘ListPrototypeCell’, I added the method ‘cellForRowAtIndexPath’ but it’s crashing with these errors:

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

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

2014-08-10 13:35:50.523 ToDoList[8954:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ListPrototypeCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

. . . .

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

I’ve been following the tutorial exactly and I can’t find the mistake. Can anyone suggest what I’m doing wrong?

enter image description hereenter image description hereThe 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;
}
1
Did you set the view controller to be the name of the class where you put this code? - user2548635
Add "Exception breakpoint" to stop on the line causing this(which should be dequeueReusableCellWithIdentifier:). Check that you implemented that method in right controller and that in Storyboard table controller has correct class. - Timur Kuchkarov

1 Answers

4
votes

Use:

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

For storyboards that's what you want. Also follow it up if necessary with:

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

Edit: If instead, you want to continue using dequeueReusableCellWithIdentifier:forIndexPath:, then in your controller's initialization you should use registerClass:forCellReuseIdentifier:, as per the docs if you are not using a storyboard. Also the (cell == nil) part has become unnecessary in the latest Xcode versions.