• 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: Another dumb question about NSWindowController(s)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another dumb question about NSWindowController(s)


  • Subject: Re: Another dumb question about NSWindowController(s)
  • From: Seth Willits <email@hidden>
  • Date: Sat, 07 Jun 2014 20:57:53 -0700

initWithWindow: is the designated initializer which is why the template has it vs one other of the init methods, but it doesn't mean you have to use it. It's not there to tell you that you need to call it, it's there so you can add initialization-time code as needed.

The easiest thing to do to get a window controller to load from a nib automatically is just implement -windowNibName. (In 10.10 you won't need to even bother if the xib is named the same as the class.)

Nothing magical going on. You (as an example) call alloc] init], it calls initWithWindow: passing nil (because it's the designated initializer). You ask for the wc's window at some point, it realizes it doesn't have one, sees windowNibName, loads from the nib, and calls windowDidLoad. Baddabing badda boom.



--
Seth Willits




On Jun 7, 2014, at 12:24 PM, William Squires <email@hidden> wrote:

>  Okay, if I create a new NSWindowController subclass (and tell Xcode to generate the .xib as well), it gives me simple (too simple, I think) template code, whose init... method takes an NSWindow reference. Where does this come from (the reference)?
>
> • Is the code instantiating the custom NSWindowController subclass supposed to allocate the NSWindow reference, and - if so - how? I thought the controller was supposed to mediate interactions between the UI and any models or other controllers, according to MVC; other code shouldn't have to worry about how or where the window comes from.
> • Or is this one of those "magical" things that's automatically hooked up when the .xib gets unarchived? If so, how, since I would think the controller would have to load the .xib first, and the template code simply contains no reference to loading (any) xib!
>
>  Unfortunately, all my "program in MacOS X...." books are really out-of-date; what with all the publishers focusing on either Android or iOS these days... :( (a look about in Barnes & Noble the other day revealed NO books on OS X programming.)
>  Could someone on this list please help me understand how a window, and its controller, are supposed to be loaded/instantiated/unarchived (that's not in the MainMenu.xib, but in a separate set of files (the header, implementation, and xib, all related by the class name)?
>
> P.S. This is with Xcode 5.1.1 on MacOS X 10.8, compiling for MacOS X 64 bit, 10.7 SDK.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Another dumb question about NSWindowController(s) (From: William Squires <email@hidden>)

  • Prev by Date: Re: Another dumb question about NSWindowController(s)
  • Next by Date: Best practices with singletons
  • Previous by thread: Re: Another dumb question about NSWindowController(s)
  • Next by thread: Best practices with singletons
  • Index(es):
    • Date
    • Thread