I can't solve "invalid nib registered for identifier (BNRItemCell)" - ios

Going through the Big Nerd Ranch iOS book, and I'm on day 2 of trying to solve this and I'm going crazy - can anyone help?
I get the following error message:
2014-06-20 11:37:18.764 Homepwner[10388:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'invalid nib registered for identifier (BNRItemCell) - nib must contain exactly one top level object which must be a UITableViewCell instance'
I've hooked up the BNRItemCell.xib to the corresponding class. Things fail after line 57 where the breakpoint is:
=======================================================
=======================================================
I know that it's gonna be something so basic that I'll kick myself.
Any help will be appreciated thanks!

Observing the TreeView on the left of the IB you have a UIView ( second top level element! ) below the UITableViewCell. Delete it and you should be fine!

I had this same issue. It turns out I had added another view by mistake on the .xib file

Related

Terminating app due to uncaught exception [UIImageView _isResizable]

I'm getting an exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView _isResizable]: unrecognized selector sent to instance 0x7fe01fd0d470'
I just assigned an image to the imageView inside a custom cell using storyboard.
The code is clean. It doesn't have any warnings or errors.
Two reason of this error.
If you want to assign image write.
cell.image=[UIImage imagenamed:#"Name of your image "];
and another reason of this error is you can cut the link of imageView to the outlet.
Again make a new outlet and then check now imageView is working.
i think this will help u.
there may be two or more outlet references to one imageView which makes ambiguous
Please see once the name of image in swift file and StroryBoard. Compare them they must be same.
Also check the identifier of Cell.

CALayerInvalidGeometry crash on iOS9 "sublayer with non-finite position [inf inf]"

iOS 9, Swift 2: I've got a view controller with a custom view that crashes whenever I pop it from it's navigation controller stack, citing the following crash:
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'sublayer with non-finite position [inf inf]'
There is far too much going on in the view controller to post here (it's what i'm in the middle of cleaning up) but was wondering if anyone has experienced a similar issue?
I've seen sublayer with non-finite position [inf inf] and a related question, but neither resolve the problem. There is no CGRectNull to be found in the entire code base, so i'm a bit stumped.
And of course as soon as I post the question after 30 minutes of struggling, I finally crack it.
There were a whole bunch of subViews that were being added to the view elsewhere in the view controller that I wasn't aware of. The main view is using constraints based layout while these subviews were being created with a frame and then added as a subview.
I'm not sure why it was causing a crash, but after removing all the rogue subviews all was well.
I'll keep this question/answer alive in case anyone else has the same issue.

Crash when tapping on UITextField or UITextView: Assertion failure in -[UICalloutBarButton layoutSublayersOfLayer:]

Answers to similar questions did not help so I'm opening a new question.
I have this issue in several of my projects now:
Tapping on the first responder UITextField or on a UITextView (that would normally bring up the default context menu for copy and paste) causes my app(s) to crash.
Note: UICalloutBarButton is a UIKit private API, so there is no chance to change its layoutSubviews implementation and call [super layoutSubviews] in it.
Log message:
*** Assertion failure in -[UICalloutBarButton layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UICalloutBarButton's implementation of -layoutSubviews needs to call super.'
I don't have any idea why this appears. Would be very happy for any help.
EDIT
Trying to reproduce the crash in a demo project I found out that it is a custom UIView category that causes the crash. See accepted answer for more details.
By trying to reproduce the crash in a demo project I found out that it is a custom UIView category that causes the crash.
When creating this fault, I assumed that category methods were only available for UIView subclasses that #import this category.
But this is not the case as described in the Apple Documentation:
Any methods that you declare in a category will be available to all instances of the original class, as well as any subclasses of the original class. At runtime, there’s no difference between a method added by a category and one that is implemented by the original class.
So not being aware of this, I had overridden in my custom category the UIView method + (BOOL) requiresConstraintBasedLayout to return YES (like I wrongly thought only for those classes that import this category).
Putting a breakpoint in that method, I learned that this 'category-method' gets called from everywhere in the UIKit once the category files are added to a project.
Nothing but a painful way of learning/accepting, that overriding methods in categories is never a good idea - unless you want to cause strange crashes like this ;-).
Sorry for stealing your time, but thank you for asking some code examples which forced me to seriously reproduce the problem - which lead me to the crash-cause...

Getting 'NSUnknownKeyException' after deleting a control and the corresponding outlet in the code

I am writing a very simple app with just one view controller. However I am getting an exception:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
Here is what I did:
added a UIImageView and created an outlet in the code by ctrl-dragging to the assistant editor.
deleted the UIImageView cause I don't need
deleted the outlet property from the code
checked the connection inspector and removed the outlet from the storyboard/InterfaceBuilder.
But I am still getting the exception as listed above, could anyone give me some hints?
Usually you should do a clean of your project, found in the Project menu next to build That way xib files get recreated and often such errors disappear.

Constraint must contain a first layout item NSLayoutConstraint

I had my LayoutConstraints working fine, then all of a sudden I started getting this when adding Constraints to my view.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint must contain a first layout item'
*** First throw call stack:
(0x7cd012 0x2017e7e 0x7ccdeb 0xde6bf1 0x9c487 0x994a3 0x414fb 0x20224 0x5c6c0 0xc30e83 0x78c376 0x78be06 0x773a82 0x772f44 0x772e1b 0x28eb7e3 0x28eb668 0x149465c 0x2cfd 0x2c25)
libc++abi.dylib: terminate called throwing an exception
And there exists no immediate documentation on the internet or on the Apple Docs as to what the error message means.
Just wondering if anyone has encountered this error, and know what I can do to troubleshoot it?
One more reason for this error/crash can be, the views passed to the [NSLayoutContraint constraintWithItem ...] method are nil.
Ah, found the issue.
For anyone who has this issue, it's because the view hasn't been created in the nib/UIView yet, so no constraints can apply.
I moved the Constraint code from the initWithNib method to viewDidLoad and the error naturally stopped occurring.
If you're hanging on to your views with properties make sure they're strong! This could account for them being nil.
This can also happen if you switch off Autolayout for some reason, but you're still adding constraints to any subview via code (e.g. for handling orientation changes)
This happened to me when I used to different NIB's for the iPhone and iPad and switched off Autolayout for only the iPhone NIB while using a common .m file.
Solution is to check for the device type and skip the layout addition where it's not needed.
This happened when I accidentally deleted the 'referencing outlet' for one of my UI elements.

Resources