Xcode unable to dequeue a cell with identifier
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.
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.
GoldXApp
Updated on July 04, 2020Comments
-
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 :
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.
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 over 10 yearsI have changed to "Basic style" to edit the "Title" in the TableViewCell. I tried with "Custom" type but same error again.
-
GoldXApp over 10 yearsIt doesn't change anything.
-
bilobatum over 10 yearsFrom your screenshot, it doesn't look like your cell prototypes are subclasses of UITableView cell. So you're not subclassing UITableViewCell?
-
GoldXApp over 10 yearsError appears for each cell : Connection "Cell1" cannot have a prototype object as its destination.
-
ssantos over 10 yearsActually, you should have just one Prototype cell. Which is the error anyway?
-
GoldXApp over 10 yearsYes, 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 over 10 yearsHere's an idea for troubleshooting: see if you can get your table cells to load without your prototypes subclassing UITableViewCell.
-
Abdullah Shafique over 10 yearsGlad you found a solution!
-
Rambatino about 9 yearsIt works when subclassing a UITableViewController. So sad that apple feels the necessity to error prone code in there.
-
Navid over 8 yearsbase on your experiment i just cleaned my project and error disappeared!!