tags:

views:

403

answers:

2

I have a view controller that is created via initWithNibName, and I just found out awakeFromNib is not called. Is awakeFromNib only called when the view controller is unarchived from the Nib? (that is, initWithCoder is called)

A: 

UIViewController loads its view lazily, only when it is needed for display. This goes for both programmatically creating the view using -loadView or unarchiving from a nib.

You can cause the view to load by referencing the UIViewController's view property.

Sean Murphy
+1  A: 

I think what you're looking for is (void)viewDidLoad. AwakeFromNib is only called on objects that are loaded from the nib. The controller itself receives viewDidLoad. Since you're calling initWithNibName, it's not actually unarchived from the nib!

Ben Gotow
I am aware of the fact that viewDidLoad will be called, but wasn't sure why awakeFromNib wasn't, because the view controller is a file owner of the NIB, so it will be unarchived and its IBOutlet and IBAction hooked up, or so I thought.
Boon
The file owner is a proxy for the UIViewController - not an actual instance. Presumably the view controller is instantiated outside of the scope of the NIB and then 'wired up' according to the relationships specified on the proxy object - the file owner.
teabot