Question

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];
}
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top