invalid nib registered for identifier (CELLNAME) - nib must contain exactly one top level object which must be a UITableViewCell instance

IosObjective CXcodeUitableview

Ios Problem Overview


Sorry for the long title, but I wanted it to be clearly seen from a google search. Also, this differs from many of the other similar questions on here as its not specifying a 'null' identifier but one that actually exists.

Essentially the problem occurs when your trying to navigate using one of the cells in a table view controller to segue to another view (Whatever that view may be).

Most people would run into this problem after gunning through the apple tutorial on the 'To-Do List' and expecting the cells to operate in the same motion regardless of their purpose. This problem is probably simplistic to most but for a beginner, its quite hard, it took me around 3 hours.

Basically the error is:

invalid nib registered for identifier (prototypeCell) - nib must contain exactly one top level object which must be a UITableViewCell instance

Where 'prototypeCell' would be whatever your cell is called. This is an exception that occurs immediately as the app is launched.

Ios Solutions


Solution 1 - Ios

I had the same problem as above but I wasn't using storyboards and the problem just appeared out of the blue.

I found that the solution was in the tableview cell file. I had added a uibutton, but it had been added outside the bounds of the cell by mistake. This meant it was almost like an extra view in the uiview.

Once I found it and deleted this extra view the problem disappeared immediately.

If you have having this error, check the uitableviewcell for extra views and objects added by mistake

Solution 2 - Ios

The answer of simon_smiley pointed me to the right direction, but some more trial-and-error was needed leading to the following solution:

The problem doesn't only occur for additional top-level UIView objects, but also for gesture recognizers. So make sure not to use any gesture recognizers in your failing XIB file, you can set them up in code instead.

For example you can do it in awakeFromNib as noted by vahotm in the accepted answers comments.

Solution 3 - Ios

I had the same problem! And in my case custom cell was the subclass of UIView by mistake instead of UITableViewCell. So replacing UIView with UITableViewCell fixed the problem!

Solution 4 - Ios

Same problem because I drag and drop a UITapGestureRecognizer on the subviews of ContentView. Just remove it.

Solution 5 - Ios

In my case, I had an extra ImageView inside the xib added by mistake. Removed it and everything worked perfectly.

enter image description here

Solution 6 - Ios

The problem is that there are multiple cells in your storyboard that have the same name. Such as for a single table view, there are multiple cells that have the same identifier. In my case I had three cells that were all called 'prototypeCell'.

The fix is actually quite easy. For every cell, name it a simple name with the cell number at the end. This cell number has to match the indexPath.row later on, so basically start from 0 onwards.

For Example:

prototypeCell0
prototypeCell1
prototypeCell2

Then, go into the class thats responsible for the controller, and find the function

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

Then replace the code:

static NSString *CellIdentifier = @"PrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

With the code:

static NSString *CellIdentifier = @"ListPrototypeCell";
NSString* num = [NSString stringWithFormat:@"%d", indexPath.row];
NSString* actual = [CellIdentifier stringByAppendingString:num];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:actual forIndexPath:indexPath];

Everything else can stay the same. This code basically gets the row number, adds it to the identifier base, the gets the cell from the table using that string. So if its responding to a different row number, it return a different cell.

Just for clarification, my whole function for the problem is as follows:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ListPrototypeCell";
    NSString* num = [NSString stringWithFormat:@"%d", indexPath.row];

    NSString* actual = [CellIdentifier stringByAppendingString:num];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:actual forIndexPath:indexPath];
    cell.textLabel.text = self.content[indexPath.row];

    return cell;
}

Good Luck!

Also, this is my first Answer/Question combo, so I really have no idea how to approach it, so if i've done anything wrong, please tell me and/or change it. Thanks!

Solution 7 - Ios

I'll put up my dumb solution for the sake of googlers...

This was my personal dumb mistake - when I created a new custom cell for my table view, I went to the top level directory of my project -> add new file -> and created an Empty File type under the OS X section rather than the iOS section.

Hopefully, most people have the other issue described above since it's less embarrassing :P

Solution 8 - Ios

Sometimes you using storyboard and have collectionView inside it and collectionView as well. After that you decide to simplified your Storyboard and divide cell into another nib. You create empty nib, Ctrl+C from storyboard -> Ctrl+V into nib.

Everything looks fine but you'll have Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (PrettyCollectionViewCell) - nib must contain exactly one top level object which must be a UICollectionReusableView instance'

Ansver: do not do this. After I clean nib and add all of elements as I've in Storyboard - it fixed.

Seems like Bug of xCode IB - Version 7.3.1 (7D1014)

Solution 9 - Ios

This error is mainly due to some extra views that are added by mistake. Have a look in the .xib file and check for extra unwanted view added by mistake. Delete that and it will work perfect. You can check for unwanted views by this is how it looks

Solution 10 - Ios

In my case, I have added UITableViewHeaderFooterView subclass and XIB in different target instead of actual target.

Make sure it is in running target.

enter image description here

Solution 11 - Ios

I solved this by setting the class name in interface builder to match the cell reuse identifier (for that class) in interface builder.

Note: I'm not saying the class and identifier have to be the same. I'm saying they need to link the corresponding view and backing model.

Solution 12 - Ios

I had this issue, finally found out that i had created UITableViewCell Subclass instead of CollectionViewCell subclass. it was evening, and i was tired,lol. Fixed it in the mng.

Solution 13 - Ios

I dragged collection view cell from other project and got this.
'invalid nib registered for identifier (cell) - nib must contain exactly one top level object which must be a UICollectionReusableView instance' .
Then i compared the collection view cell from created my me and found reusable view missing. Hope this help.
enter image description here

Solution 14 - Ios

It was a silly mistake on my side and I had two tableview cells which caused this error. Removed the other 'table view cell' which fixed the issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCail DemetriView Question on Stackoverflow
Solution 1 - Iossam_smithView Answer on Stackoverflow
Solution 2 - IosJeehutView Answer on Stackoverflow
Solution 3 - IosAnnieView Answer on Stackoverflow
Solution 4 - IosWilliam HuView Answer on Stackoverflow
Solution 5 - IosabhimuralidharanView Answer on Stackoverflow
Solution 6 - IosCail DemetriView Answer on Stackoverflow
Solution 7 - IosRyhanView Answer on Stackoverflow
Solution 8 - IosWINSergeyView Answer on Stackoverflow
Solution 9 - Ios2rahulskView Answer on Stackoverflow
Solution 10 - IosMohammad Zaid PathanView Answer on Stackoverflow
Solution 11 - IosAndrew KirnaView Answer on Stackoverflow
Solution 12 - Iosck8414View Answer on Stackoverflow
Solution 13 - Iosuser1039695View Answer on Stackoverflow
Solution 14 - IosStephen SelvarajView Answer on Stackoverflow