0

Its works fine on iOS 6 simulator. On iOS 5.1 Simulator when i run it for the very first time it get crashed due to the following exception.

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

Here's my code

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";

    cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
        }
        else{
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
        }
        cell = nibLoadCellForListDetails;
    }
    return cell;
}

And in listTableCell.xib I set the File's Owner as my table view controller. And i made an outlet as nibLoadCellForListDetails in my table view controller correctly.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
Mohan Kumar
  • 334
  • 1
  • 4
  • 10

2 Answers2

1

Looks like no cell has actually been created. Add in:

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

instead of:

cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
Cocoadelica
  • 3,006
  • 27
  • 30
0

Give a try like this

if (cell == nil) {
    NSArray *nib;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

      nib =   [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
    }
    else{
      nib =  [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
    }
    cell = [nib objectAtIndex:0];
}
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110