NSWindow

Discussion in 'Mac Programming' started by satyam90, Jan 21, 2008.

  1. satyam90 macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    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.
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    -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.
     
  3. satyam90 thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    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.
     
  4. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #4
    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.
     
  5. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #5
    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.
     

Share This Page