Xcode unable to dequeue a cell with identifier

74,528

Solution 1

Instead of:

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

Try:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if this does not work then, also add:

  if (cell == nil) {
    cell = [[customCell alloc] init];
}

Solution 2

Ok, your problem is that you're using Static cells, instead of Prototype cells. Just change your UITableView Content type.

Prototype cells option

Solution 3

Ok, my project finally works. Some errors appeared about things I've deleted and I can't find anymore.

I've just deleted every TableViewCell I had to create a new unique UITableViewCell with the following properties :

class : customCell

Style : Basic (but it works also with Custom)

Identifier : Cell1

Thanks for your help ssantos, Abdullah Shafique and bilobatum.

Solution 4

I suppose you'r using static cells. If you'r doing that consciously - just delete thous methods from your .m file:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}

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

Solution 5

If your table cell is a subclass of UITableViewCell, then you're not using the "Basic" style of cell. Change the style setting in the attributes inspector to Custom.

Also, make sure the Class in the table cell's Identity inspector is set to your custom table cell subclass.

Share:
74,528
GoldXApp
Author by

GoldXApp

Updated on July 04, 2020

Comments

  • GoldXApp
    GoldXApp almost 4 years

    my work is about `UITableView. Each time I run my project, this error appears :

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

    I checked a hundred times my cell identifier in my storyboard and in my code are the same. Code (defaut code from UITableViewController) :

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
        static NSString *CellIdentifier = @"Cell1";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
        // Configure the cell...
    
        return cell;
    }
    

    Picture of Table View Cell properties : enter image description here

    I created and implemented a subclass of UITableViewCell for my cell.

    Any idea why this is not working ?

    Any way (line of code) to know what is the identifier of a cell ?

    Thanks

    Edit : Screenshot of my interface builder.

    IB

    Edit 2 : Text of customCell.h

    #import <UIKit/UIKit.h>
    
    @interface customCell : UITableViewCell
    
    @end
    

    New error appears when I run the project :

    [<choixActiviteViewController 0x7591ac0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Cell1.
    

    choixActiviteViewController is a subclass of UITableViewController and is the custom class of Choix Activite View Controller.

  • GoldXApp
    GoldXApp over 10 years
    I have changed to "Basic style" to edit the "Title" in the TableViewCell. I tried with "Custom" type but same error again.
  • GoldXApp
    GoldXApp over 10 years
    It doesn't change anything.
  • bilobatum
    bilobatum over 10 years
    From your screenshot, it doesn't look like your cell prototypes are subclasses of UITableView cell. So you're not subclassing UITableViewCell?
  • GoldXApp
    GoldXApp over 10 years
    Error appears for each cell : Connection "Cell1" cannot have a prototype object as its destination.
  • ssantos
    ssantos over 10 years
    Actually, you should have just one Prototype cell. Which is the error anyway?
  • GoldXApp
    GoldXApp over 10 years
    Yes, I think I do. In my IB, each cell has "customCell" in their custom class (in Identity inspector). In customCell.h : @interface customCell : UITableViewCell
  • bilobatum
    bilobatum over 10 years
    Here's an idea for troubleshooting: see if you can get your table cells to load without your prototypes subclassing UITableViewCell.
  • Abdullah Shafique
    Abdullah Shafique over 10 years
    Glad you found a solution!
  • Rambatino
    Rambatino about 9 years
    It works when subclassing a UITableViewController. So sad that apple feels the necessity to error prone code in there.
  • Navid
    Navid over 8 years
    base on your experiment i just cleaned my project and error disappeared!!