IOS 5 Storyboard Custom Cell Crash: UITableView dataSource should return a cell

This is either an Xcode error, or I do not see a key rule here.

Update: - What is the likelihood that this will be a strange error in Xcode / Storyboard?

Situation:

  • iOS 5 storyboard
  • This is the storyboard setting: http://i.imgur.com/T5WyD.png
  • Another screenshot of the full setup: http://i.imgur.com/1tVuz.png
  • TableViewController with a custom cell, the cell has a reusable identifier "NewCell"
  • in "cellForRowAtIndexPath" I basically have:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewCell"]; return cell;

  • This throws an exception:

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

Things I've already tried:

  • , TabBarController, TableViewController Custom Cell, Storyboard, . , , . , ...

, - , , TabBarController, NavigationController, TableViewController, , , TableViewController, , -.

:- , :    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewCell"]; NIL ( /iOS 4). , . , , , .

+5
5

, , . UITableView ViewController in Story, , .

  • "ViewController.h" <UITableViewDataSource>

    @interface ViewController: UIViewController <UITableViewDataSource>

    , <UITableViewDelegate>, .

  • "ViewController.m" Table view

    #pragma mark - Table view data source
    
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        // Return the number of sections.
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // Return the number of rows in the section.
        return [yourCells count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        NewCell *cell = (NewCell *)[tableView 
                                               dequeueReusableCellWithIdentifier:@"NewCell"];
        if (cell == nil) {
            NSLog(@"Cell is NIL");
            cell = [[CustomCell alloc] 
                    initWithStyle:UITableViewCellStyleDefault 
                    reuseIdentifier:CellIdentifier];
        }
    
        return cell;
    
    }
  • Storyboard UITableView " " "" ViewController.

  • Cell "NewCell"

, , .

, =)

+2

:

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
return cell;

, / . , , - UITableViewController .

+1
  • "NewCell"?
  • Tabbar- > navigationcontroller- > tableview . .
  • ,
    ViewController/TableView/.
  • - UIButton ? ?
0

, dequeueReusableCellWithIdentifier:

static NSString *CellIdentifier = @"NewCell";

, Storyboard

0

Perhaps the answer later, but I bet it will eliminate all of your problems

0
source

All Articles