简体   繁体   中英

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)

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM