Reputation: 41470
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)
Upvotes: 8
Views: 8349
Reputation: 14884
I think what you're looking for is viewDidLoad
. awakeFromNib
is only called on objects that are loaded from the nib. The controller itself receives viewDidLoad:
. Since you're calling initWithNibName:bundle:
, it's not actually unarchived from the nib!
Upvotes: 18
Reputation: 2520
awakeFromNib is not called for placeholder objects such as File's Owner and First Responder in iOS. See #4 in the Object Loading Process Docs
Upvotes: 2
Reputation: 2761
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.
Upvotes: 4