0
votes

I am trying to load a UITableViewController however i keep getting this error and my app crashes.

* Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439 2014-04-15 00:40:55.244 TradingGame[966:60b]* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

Heres my code

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

Here is where i call my UITableViewController to push to the screen:

    if (indexPath.row == 1) {
    Foo *foo = [[Foo alloc] init];
    [self.navigationController pushViewController:foo animated:YES];
}
1
Have you defined a custom class for your table view controller?javierfdezg
Yes its a subclass of UITableViewControllerJH95
Double check that your prototype cell appears under your tableview in the storyboard object navigator - it looks correct from the image. Also make sure that you have actually instantiated your UITableView from the storyboard and not some other UITableViewPaulw11
Yeah its there. Il post code showing how i have instantiated my UITableView.JH95

1 Answers

3
votes

Problem solved. Thanks to @Paulw11 for pointing out about instantiating the table view. Those who have a similar issue to me make the following changes to your instantiation of tableview: Try this first:

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

If that does not work you may have a similar problem to me therefore use this code:

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

Replace classes where applicable and "Foo" should be equal to the Storyboard ID of the view controller you are trying to instantiate.