Boon
Boon

Reputation: 41470

awakeFromNib is not called in my ViewController

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

Answers (3)

Ben Gotow
Ben Gotow

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

Michael Enriquez
Michael Enriquez

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

Sean Patrick Murphy
Sean Patrick Murphy

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

Related Questions