• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: initializing a Window Controller
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initializing a Window Controller


  • Subject: Re: initializing a Window Controller
  • From: Dustin Voss <email@hidden>
  • Date: Tue, 17 Feb 2004 16:42:47 -0800

On 17 Feb, 2004, at 10:28 AM, Robb Bean wrote:

Hello!

I'm new to Mac OS and I'm also new to programming under Mac OS and Cocoa, so please tell me if the following is a "RTFM" question.

I'm writing an application that contains a main window which needs to be initialized at program start up, concrete, I read values from a database and store them into a NSComboBox. Using the Cocoa example application from the documentation, the currency converter, I gave my program a controller called MainWindowController; its task is to react on button clicks and reading/writing compoment values, such as text fields. This all works very well, but the initialization. I added a -init: message to the MainWindowController in expectation that it is executed on window creation. A puts() shows me that -init is called, but I don't see the values assigned to the control. To test a bit around this I assigned the -init message with an additional button click: If I click the button, the window is initialized correctly, that means inserting the values from the database into the combo box works.

My questions are now:
* Is it possible that the component values are setted _after_ the execution of -init, that means that my values are overwritten?
* How do I initialize a window without using a special button click?

Windows are usually populated in an method called -awakeFromNib. -awakeFromNib is called while loading the NIB, after all outlets have been connected. -init is called before the outlets are connected, which is why it didn't work.

-awakeFromNib is usually implemented in your window controller. When Cocoa loads a NIB, it calls -awakeFromNib on the NIB File's Owner and every object in the NIB (which is where your window controller will be if you followed the Currency Converter example). So implement -awakeFromNib in your window controller and set the contents of the combo box there.

This is documented, but it is also very easy to miss. If you want to learn more about the process, check out the docs for AppKit's NSNibAwaking informal protocol.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: initializing a Window Controller
      • From: Chris Hanson <email@hidden>
References: 
 >initializing a Window Controller (From: Robb Bean <email@hidden>)

  • Prev by Date: Re: kqueue on OS X
  • Next by Date: Re: Insert two objects under the same column
  • Previous by thread: initializing a Window Controller
  • Next by thread: Re: initializing a Window Controller
  • Index(es):
    • Date
    • Thread