View Full Version : NSWindow
satyam90
Jan 21, 2008, 06:49 AM
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
Jan 21, 2008, 10:58 AM
-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
Jan 22, 2008, 05:18 AM
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
Jan 22, 2008, 09:44 AM
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
Jan 22, 2008, 09:49 AM
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.