0

I got the following exception:

Fatal Exception: NSInternalInconsistencyException UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

My tableview has custom cells. Usually this code works. However, the exception happened only once.

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

    // Get the cell to populate
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"appt"];

    if (!cell) {
        // Create new cell
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"appt"];

        // Populate from NIB
        UINib* nib = [UINib nibWithNibName:@"ScheduledRowView" bundle:nil];
        NSArray* views = [nib instantiateWithOwner:nil options:nil];
        UIView* parent = [views objectAtIndex:0];
        CGRect rowRect = parent.frame;
        rowRect.size.width = tableView.frame.size.width;
        parent.frame = rowRect;
        cell.frame = rowRect;
        [cell addSubview:parent];
    }

    // Populate the cell
    // Code for populating cell..

    return cell;
}
Carl
  • 183
  • 1
  • 15
  • can you reproduce the error? – matteok Dec 05 '14 at 19:11
  • 1
    remove the line `if (!cell) {` and run... you will see it running... – Fahim Parkar Dec 05 '14 at 20:52
  • BLAST FROM THE PAST! OMG why would somebody use NIB when there is Storyboard available since iOS 5. Anyway, this Q was asked a million times before and you do it in some perverted way. http://stackoverflow.com/a/10088146/351305 – pronebird Dec 05 '14 at 23:27
  • possible duplicate of [Loading a Reusable UITableViewCell from a Nib](http://stackoverflow.com/questions/413993/loading-a-reusable-uitableviewcell-from-a-nib) – pronebird Dec 05 '14 at 23:27

0 Answers0