I am loading a UIViewController
from a bundle with initWithNibName:bundle:
. If I set a breakpoint in its viewDidLoad
I can see that its view
is set. I can also see this when viewing About.xib
in the Interface Builder.
However once the view is actually used for the first time (in a call to [self.navigationController pushViewController:viewController animated:YES]
according to my app's logic) I get this error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "About" nib but the view outlet was not set.'
This is the call that also triggers viewDidLoad
. So apparently during the call, view
is first non-nil (as it should be) and later apparently becomes nil again.
If I alternatively type po [viewController view]
in the debugger immediately prior to the call I get this error (which is presumably just another presentation of the same symptom):
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3).. The process has been returned to the state before expression evaluation.
How can I load and use the view controller in conjunction with an existing navigation bar without running into these errors?
UPDATE The problem apparently disappears if I load the view controller from my a storyboard (not necessarily my main storyboard) instead of from a XIB file.
When viewing the xib file in Xcode, in the identity inspector, is the custom subclass set to you view controller's class? If you set that, then go to the connections inspector, you will see an attribute called "view", just drag that to your view in Interface builder and it should work
My guess is that you were overriding some default UIViewController
behavior, either make its view
a weak
property, a strange loadView
method or just not calling super
in one of your overridden methods.
Another common error is calling a non-matching super
method (call super viewDidLoad
from an awakeFromNib
, etc.) which could happen when you move code around or after trying different things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With