Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 698
Cail Demetri Avatar asked Dec 07 '13 14:12

Cail Demetri


4 Answers

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

like image 107
sam_smith Avatar answered Nov 19 '22 19:11

sam_smith


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.

like image 38
Jeehut Avatar answered Nov 19 '22 21:11

Jeehut


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!

like image 8
Annie Avatar answered Nov 19 '22 19:11

Annie


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

like image 8
William Hu Avatar answered Nov 19 '22 21:11

William Hu