user2234629
user2234629

Reputation: 29

awakeFromNib() and windowDidLoad()

Can anyone explain what awakeFromNib(), windowDidLoad(), init() does? I am using a class which is inherited from NSWindowController, i found the precedence as -init(), -awakeFromNib(), -windowDidLoad(). I want to know what these methods exactly perform.

Upvotes: 0

Views: 1121

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

init is the first method that gets called. This initializes self and all the ivars, properties etc.

awakeFromNib is called after init. When a nib is loaded, the nib loader allocates and initializes all objects, then hooks up all of their outlets and actions. Because of the order in which this happens, you cannot access outlets in your initializer. You can try, but they will all be nil. After all outlets and actions are connected, the nib loader sends awakeFromNib to every object in the nib. This is where you can access outlets to set up default values or do configuration in code.

windowDidLoad is a delegate method which is called when window is fully loaded. Sent after the window owned by the receiver has been loaded. The default implementation does nothing.

Upvotes: 3

Related Questions