Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
Hi,

Can anyone tell me what is the order in which the functions are called related to window:

1. windowDidUpdate
2. windowDidBecomeMain
3. awakeFromNib

Also can you please tell me when "init" will be called.
I have gone through documentation and got confused. Please clarify my doubt.

regards,
satyam.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
-init is always called first—you can't have an object unless init is called... (in NSWindow's case, of course, it's not -init, but -initWithContentRect:styleMask:backing:defer: ). However, if the window is being loaded from a nib, the nib-loading code is responsible for calling -initWithCoder: when the window is opened for the first time.

Once the entire nib-loading process is complete, -awakeFromNib is called on every object loaded (including the window).

-windowDidUpdate is sent to the window's delegate (according the documentation for -update) on the event loop directly prior to the window being drawn, so that would have to come after the -awakeFromNib message.

I would expect that -windowDidBecomeMain would come next, since the window has to be drawn onscreen for it to become main. Of course, this could be called many times—not just when the window is first loaded.
 

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
Thanks for the information.
What I want to do in my application is:
I have a UI with combo box and few other controls which has a window controller associated with UI. I am creating singleton class of UI. Then I will set the default values of some variables inside the class using a method and will call showWindow.
According to some of the variable's values, the combo box has to be updated before loading the window and display it. (Eg: As updating city names in combo box depending on state name).
So, which delegate method I have to use here. Also this delegate has to be called only once while creating and displaying window.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
Well, you can't set default values for the controls before the window is loaded. However, you can set it before it is displayed on screen. You can override -windowDidLoad on your NSWindowController and set all your default values there.

Optionally, if the window controller is also in the nib, you can override -awakeFromNib and set everything there.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
windowDidBecomeMain is actually slightly before windowDidUpdate is first called, though that gets called lots of times.

The problem with windowDidBecomeMain is that the window is still white when it is called, so if you want to display a sheet or something you have to use windowDidUpdate. I use a bool which is checked first so that it doesn't loop through all my code each time windowDidUpdate is called.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.