0

I created a tableviewcontroller to handle 4 static cells in a tableview. The tableview is positioned right below the 4 cells. However the last cell, 4th cell, is optional based on the 3rd cell's result.

The picker returns a value and when it does, it reloads the tableview to activate the 4th cell should the value be correct.

SettingsViewController

When I run the app it crashes on loading the SettingsViewController with this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

I thought I didnt need reuse identifiers if I had static cells?

Here is the relevant code:

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(self.showLastCell)
    {
        return 4;
    }
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}
marciokoko
  • 4,988
  • 8
  • 51
  • 91

2 Answers2

0

Dequeuing cells are for table view with dynamic cells. It is not necessary for static cells table view to have the data source cellForRowAtIndexPath. So you can safely remove the data source method cellForRowAtIndexPath.

Check this question for more explanation: Storyboard static cells: dequeueReusableCellWithIdentifier returns nil

Or you can use the super method as mentioned here: UITableView with static cells without cellForRowAtIndexPath. How to set clear background?

Community
  • 1
  • 1
Valent Richie
  • 5,226
  • 1
  • 20
  • 21
0

You don't need to dequeue it, as you said, it's only static cells.

Instead of :

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Use :

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Good luck !

EDIT : Too slow !

DCMaxxx
  • 2,534
  • 2
  • 25
  • 46