Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath / Assertion failure messages

Tags:

uitableview

Implemented UITableView with custom UITableViewCell with below code

    @interface ProfileSaveViewController : UITableViewController
     {
         UITableViewCell *cell0;
         UITableViewCell *cell1;
         UITableViewCell *cell2;
         UILabel *cell2Label;
     }

    @property (nonatomic, retain) IBOutlet UITableViewCell *cell0;
    @property (nonatomic, retain) IBOutlet UITableViewCell *cell1;
    @property (nonatomic, retain) IBOutlet UITableViewCell *cell2;
    @property (nonatomic, retain) IBOutlet UILabel *cell2Label;

    @end

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:               (NSIndexPath*)indexPath
  {
        if([indexPath row] == 0) return cell0;
        if([indexPath row] == 1) return cell1;
        if([indexPath row] == 2) return cell2;   
        return nil;
  }

follwing message came when running the application.

* Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2012-03-01 11:11:31.984 TestSplitView[765:f803] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

like image 660
Susitha Avatar asked Dec 13 '22 04:12

Susitha


1 Answers

You're being asked for a cell and returning nil (or maybe something else that's not a UITableViewCell). It's just that simple.

I see two possibilities:

  • You are returning a number larger than 3 from tableView:numberOfRowsInSection:. Don't.

  • One or more of your cell# outlets is not hooked up in your nib, or is not hooked up to a UITableViewCell (or subclass). Hook them up properly.

like image 182
rob mayoff Avatar answered May 30 '23 12:05

rob mayoff