Question

I dont understand this: my cellForRowAtIndexPath: indexPath: returns a proper UITableViewCell. (I have an assertion to the effect that it is not nil and a trace to prove it)

But I am stil getting this sporadic exception?

This is how I allocate / reuse the cell:

...
{
  UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier: cellIdentifier];
  if (cell == nil)
  {
      cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
                                     reuseIdentifier:  cellIdentifier] autorelease];
      cell.selectionStyle = UITableViewCellSelectionStyleNone;
  }
  assert(cell);
  // (code to populate cell)
  // ...
  assert( cell != nil);
  NSLog(@"returning cell %@ type %@", cell, NSStringFromClass([cell class]));
  // edit: showing actual return value
  return cell;
}

The crash looks like this in the log:

2013-04-17 16:46:05.323 .. -[SomeEditViewController tableView:cellForRowAtIndexPath:] returning cell <UITableViewCell: 0x20d1a2e0; frame = (0 351; 320 43); hidden = YES; autoresize = W; layer = <CALayer: 0x20d1a410>> type UITableViewCell
2013-04-17 16:46:15.296 ... *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:5471
2013-04-17 16:46:15.301 ... *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

I have looked at numerous other entries with a similar question. I am stumped! I did my homework, ensuring that the cell that I returned was not nil, and still I get this assertion!

Anyone can help with this? Thanks

Was it helpful?

Solution

It turns out that I did return the cell after all (as far as cellForRowAtIndexPath: is concerned)

The problem was solved by assigning the tableView.datasource and tableView.delegate to nil in dealloc.

The table view was most likely still pending dealloc when the container view controller was deallocated, and it could not call my cellForRowAtIndexPath implementation. At least, I was able to reproduce the problem (and the fix).

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