Reputation: 1919
I've been trying to verify in my tests (GTM) that when a nib file is loaded, its IBOutlets were properly connected in InterfaceBuilder.
However I keep getting nil references, despite calling [myViewController viewDidLoad] before asserting that the reference should exist.
Are there any gotchas here, or should this be mocked somehow ?
cheers
Upvotes: 6
Views: 1069
Reputation: 8323
calling [myViewContoller viewDidLoad]
does not load the view. You want [myViewController loadView]
, which loads up the .nib and the references.
Upvotes: 10
Reputation: 33592
You shouldn't be calling -viewDidLoad.
If by "when a nib file is loaded", you mean you're calling -initWithNibName:bundle:, that does not load the nib. That just sets the nib name that is used to load the view. The "correct" way to load the view is to call -[UIViewController view] (which calls loadView if it was not already loaded, which by default loads from the nib, which has a default name of [[self class] description] or so, I think). -[UIViewController view] will call viewDidLoad for you.
Upvotes: 3