Re: NSWindowControllers and NSWindow
Re: NSWindowControllers and NSWindow
- Subject: Re: NSWindowControllers and NSWindow
- From: Ken Thomases <email@hidden>
- Date: Mon, 16 Feb 2015 13:28:46 -0600
On Feb 16, 2015, at 11:55 AM, Dave <email@hidden> wrote:
>> You never want a NIB for the window controller that's separate from the NIB containing the window. You want a single NIB for the window which the window controller will load and be the owner of. The NIB will *not* "contain" the window controller. The File's Owner placeholder in the NIB represents the window controller, but the window controller will be created before the NIB is loaded and will, in fact, be the thing which loads the NIB.
>
> This is what I don’t get! If I have:
>
> LTWViewController.h and LTWViewController.m, and LTWWindow.xib, then set the file owner in the NIB to “LTWViewController”, how do I then wire up outlets, bindings and actions so that I get properties set in LTWViewController?
Well, you've switched from talking about a window controller to a view controller for some reason. That aside, when you set the class of File's Owner that lets IB know what outlets and action methods the File's Owner supports. So, if you have set the class of File's Owner to LTWViewController (to follow your example), then the File's Owner placeholder now has whatever outlets you have defined on the LTWViewController class. You connect the outlets from the File's Owner placeholder to whatever object they are supposed to reference.
When a window controller loads a NIB, it typically provides itself as the owner of the NIB. That means that the NIB loading machinery will use that window controller as the real object that the File's Owner placeholder was holding the place for. So, any outlet connections established in the NIB from the File's Owner placeholder will actually set the properties of the window controller (assuming they exist). Any controls whose actions were connected to the File's Owner placeholder as the target will actually have their target set to the window controller. Etc.
Likewise for a view controller, but the NIB should only contain a view in that case, not a window.
> I can see I could do it if I had LTWViewController.xib that included an NSWindow?
Huh? Why does the name of the NIB file make a difference?
> Thanks a lot.
You're welcome.
Regards,
Ken
_______________________________________________
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