I have a storyboard in a project I am working on, but recently I have noticed that I am having issues. Out of nowhere, my code is now telling me I need to register a class for a cell identifier
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier rootCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
(I have the cell prototype in the storyboard, so I don't believe I need to.) if I perform
[tableView registerClass:<my class> forCellReuseIdentifier:<identifer>];
it will get beyond that, but then it hangs up when I
[self performSegueWithIdentifier:<my ID> sender:self];
and tells me that it cannot find the segue. I was able to confirm the segue is setup with the proper Identifier in the storyboard.
Does anyone know what the problem could be?
I did a rename on the storyboard a while back, but I updated info.plist and I'm pretty sure it still worked after that.
If I re-create the storyboard in another project, it works fine, but if I re-create the storyboard in this project, it fails.
EDIT: I do have the class set correctly in IB
also this is a manual segue.
EDIT: Added exact error wording.
I just had this happen.
Had to add [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"WhateverCellID"]; in my viewDidLoad
I was using a regular viewController, realized my mistake, and switched to a tableViewController and started getting the same error.
Alternatively use 'UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];`
Without the indexPath option this is a different call, which doesn't require registration and may suit your needs.
If you delete the storyboard from your iPhone/iPad/Simulator or wherever you're debugging it, and then clean in Xcode, then build & run, do you see different results? The reason I ask is that each time you build in Xcode, you get a union of everything your project has ever contained. So if you renamed the storyboard, and haven't done a full clean, you likely have both storyboards in your built product.
Related
Problem such, downloaded and installed MWFeedParser, it worked all right, but that's a problem, I do not need that to show a list of the main xib news, and that he would need to show the menu that I create. But when you try to add a menu, ie create a new a new xib, I choose in the settings (general) in paragraph mainintarface, choose your new xib (MainNav) I get an error
libc++abi.dylib: terminating with uncaught exception of type NSException
Dig deeper into the net, I came across this response, I understand the problem is that I have not added my new xib in UICollectionView? I porobyval remove UIKit.framework, then got out unreal number of errors. Well, actually the question how do I add my new xib in UICollectionView?
You need register your xib cell to your UICollectionView on -(void)viewDidLoad of your view Controller.
[self.collectionView registerNib:[UINib nibWithNibName:#"nibName" bundle:nil]
forCellReuseIdentifier:#"cellIdentifer"];
Click [here] (https://github.com/lequysang/TestCollectionViewWithXIB")
I am doing a UICollectionView project but I didn't use storyboard to manage the views. I subclassed a UICollectionViewController in MyCollectionViewController with a MyCollectionViewController.xib file created. In the xib file, I dragged a Collection View onto the view, as the figure shown.
I believe that the grey boxes are the Collection View Cells and I am supposed to click on them and change their Identifier so that these two lines of code recognize this is the cell.
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"CollectionViewCell"];
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:#"CollectionViewCell " forIndexPath:indexPath];
However, I couldn't click on the cells neither can I drag a new Collection View Cell onto the Collection View. I am getting the error message like this:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier CollectionViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Can someone help me?
I figured it out.
The reason was I have used duplicated cell identifier: #"CollectionViewCell".
Change it and everything is working perfectly!
So, be aware of the identifiers! Make sure that each one is unique and don't even mess up with class names. Hopefully this can help out some people who have the same problem as me.
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.
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
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.
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!
Same problem because I drag and drop a UITapGestureRecognizer on the subviews of ContentView. Just remove it.
In my case, I had an extra ImageView inside the xib added by mistake. Removed it and everything worked perfectly.
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!
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
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)
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
In my case,
I have added UITableViewHeaderFooterView subclass and XIB in different target instead of actual target.
Make sure it is in running target.
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.
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.
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.
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.
Collection Reusable Views, including Collection View Cells (which is a subclass), have a field in Interface Builder called "Identifier" with prompt "Reuse Identifier".
However, you normally use it by registering it with the UICollectionView using the –registerNib:forCellWithReuseIdentifier: and –registerNib:forSupplementaryViewOfKind:withReuseIdentifier: methods, where you also specify a reuse identifier.
So then what's the point of setting one in Interface Builder? It seems to make no difference whether you set it there or not.
If you implicitly load a collection view from a storyboard you only have to do
UICollectionView *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:#"CollectionViewCell" forIndexPath:indexPath];
to get the cell. You don't need to call registerNib:. This only works if you set a reuse identifier.
For NibCell (UICollectionView in a Nib) you must use registerNib:, that's only way.
If you give your Cell in Nib a reuse identifier, this identifier must same in register so better leave it blank.
-Cell by Code: registerClass
-Cell in Nib(Xib) registerNib
-Cell in StoryBoard: don't register
One more answer of mine here
In the viewDidLoad of viewContoller
register class or Nib of uicollectionview with Reuse Identifier
and use the same in
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
yes i agree it makes no difference to setting in the Interface Bulider but if set in the Interface Builder and use a different in your code than it would make a difference.
I just came across a situation myself where there most definitely is a difference in behaviour between having the reuse identifier set in Interface Builder and not having it set. (This is along the lines of what #LESANG is alluding to in their answer; that the reuse identifier should be left blank when creating cells in a separate nib file. I wanted to include some more details of when/why this is the case)
In my case, I had a custom cell that I wanted to be usable by multiple different view controllers. In order to share the cell, I created a separate nib file for the cell, configured the view hierarchy, and assigned a reuse identifier in Interface Builder. Each view controller then registers the cell using register(_:forCellWithReuseIdentifier:), and passing in the same reuse identifier as set in IB.
However, for one of my view controllers, I actually wanted to register different cells (different reuse identifiers) but using the same nib*. But simply passing in a different reuse identifier causes the app to crash, complaining:
view reuse identifier in nib (<reuse identifier in nib>) does not match the identifier used to register the nib (<reuse identifier when registering programmatically>)
So to solve this, there must be no reuse identifier specified in the nib itself. By removing the identifier in the nib, the identifier specified in register(_:forCellWithReuseIdentifier:) is used instead, and cells are dequeued correctly.
It's worth noting, therefore, that when defining cells in nib files, there appears to be no point whatsoever in coding the reuse identifier into the nib – any views that want to use that cell must register it manually in code anyway, at which point the reuse identifier specified there might as well be used rather than the one in the nib. In this scenario, it seems that all the identifier in the nib does is take precedence over the programmatically registered identifier, and cause a crash should you attempt to use a different identifier.
*Sure, I could create a new nib file with the same/similar view hierarchy and a different reuse identifier, but then should I need to change the cell configuration I'd have to make the same change across multiple files.
I would like to create a UIViewController with various options, each can be enabled/disabled with a UISwitch.
I'm using Xcode 5 and iOS 7 deployment target.
The UITableView contains static cells. The interface is created in a storyboard.
When I'm adding a UISwitch to a cell (to it's contentView) I get this error:
Exception while running ibtool: *** setObjectForKey: object cannot be nil (key: objectID)
Isn't it possible to add a UISwitch to a static UITableViewCell?
When removing the UISwitch the error disappears.
I have the exact problem today and I couldn't figure out what is causing my problem because I have added too many items on my view controller. Now I know it is the UISwitch.
But I have resolved the problem, nonetheless.
I disabled the "Accessibility" option and the build was successful.
But How come the "Accessibility" option becomes an issue of Object Id remains unclear.
For static table cells one has use to a UITableViewController. Static cells are not supported by UITableView.
Another answering this point: https://stackoverflow.com/a/9428324/42756
A bit late but to the game, but...
If you define a User Defined Runtime Attribute to an AutoLayout constraint that is a Placeholder (i.e. removed at build time), you get this error.