0
votes

I have an table view where i am loaded custom cell from different nib, i am getting exception:

 2011-05-18 18:01:00.323 custInfoService[4370:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709
2011-05-18 18:01:00.324 custInfoService[4370:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
2011-05-18 18:01:00.325 custInfoService[4370:20b] Stack: (
    11125851,
    2442997307,
 

When i used breakpoint then i come to know the xception is in switch case.I am not able to figure out why its giving exception?? help me! here is my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
        [[NSBundle mainBundle] loadNibNamed:@"BookDetailViewController" owner:self options:NULL];
        cell = nibloadedcell;
       }

    tbcel.layer.cornerRadius = 10;
    tbcel.text = aBook.Name;


    UILabel *fieldlabel = (UILabel *) [cell viewWithTag:1];
    fieldlabel.text = [fieldarray objectAtIndex:(indexPath.row)];
    UILabel *valuelabel = (UILabel *) [cell viewWithTag:2];
    switch(indexPath.section)

    {
        case 0:
            valuelabel.text = aBook.Address;
            break;
        case 1:
            valuelabel.text = aBook.Phone;
            break;
        case 2:
             valuelabel.text = aBook.Purchase;
    }

    return cell;
}

1

1 Answers

0
votes

So the most obvious problem is that

[[NSBundle mainBundle] loadNibNamed:@"BookDetailViewController" owner:self options:NULL];
cell = nibloadedcell;

is not setting your nibloadedcell outlet, so cell is nil all the way through. Hence no valid cell is returned, and you get the error UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:.

Don't forget, messages to nil are silently disregarded - the rest of the function can execute fine if cell is nil, and just not do anything!