Re: I want a window's file owner that's not a NSWindowController
Re: I want a window's file owner that's not a NSWindowController
- Subject: Re: I want a window's file owner that's not a NSWindowController
- From: Quincey Morris <email@hidden>
- Date: Tue, 28 Sep 2010 11:02:19 -0700
On Sep 28, 2010, at 10:41, Jonny Taylor wrote:
> I am trying to understand the right way of dealing with a "settings" window in my application. I have a "Camera" object that wraps a Firewire video camera. I would like to bring up an NSPanel that enables various settings of the camera to be modified. I do not need to override any particular behaviours of NSWindowController, and it seems to me that logically my Camera object should not need to inherit from NSWindowController (the window business is a bit of a distraction from the main purpose of the camera class, which is handling received frames - and in future I may want more than one such camera-related window).
>
> What I thought I could do when I want to bring the settings window up is as follows (from within my Camera class):
> if (settingsWindowController == NULL)
> settingsWindowController = [[NSWindowController alloc] initWithWindowNibName:(NSString *)@"Camera Settings" owner:self];
> [settingsWindowController showWindow:self];
> (where settingsWindowController is an instance variable of type NSWindowController). In the nib file I have set the File's Owner proxy to type Camera, and the bindings I have set up for the window all work correctly. However [settingsWindowController window] returns nil, and this causes various problems. Clearly I am doing something wrong.
>
> Alternatively I can set the File's Owner to type NSWindowController (and not specify an owner in my call to initWithWindowNibName). If I do this then the window controller is correctly linked to the window (I link up the appropriate outlet in IB), but the bindings don't work.
>
> I can't work out whether there is a way I can get my (instance variable-based) window controller to work AND bind to the Camera object. I feel this would be the tidiest way of doing things (it doesn't make sense to me for Camera to inherit from NSWindowController). Is there something extra I need to do to make this work, or am I just approaching all this in the wrong way?
>
> I have tried adding an NSWindowController object in the nib (with File's Owner still Camera). I can wire that up to the window, but I suspect that's not doing anything because I am allocating my own NSWindowController object in the code I listed earlier. I wonder if adding the NSWindowController object is the way forwards - but if so, how to I go about loading the controller from the nib as well as the window itself? I suspect from various other confused postings in the archives that initWindowWindowNibName:owner may not be the right thing for me to use here.
You're kind of mixing up two different tasks here. The Camera object is (likely) part of your data model (in the MVC paradigm). A window controller is a ... controller. For your settings window, you'll have least heartache if you make the NIB's File's Owner a window controller. Window controllers are *designed* to be the owners of NIB files.
So, subclass NSWindowController, and add a "camera" property. (Your Camera object can pass its 'self' pointer as a parameter to the window controller subclass's init... method.)
Then, to get at Camera properties, objects in the NIB can bind to File's Owner.camera.whateverProperty -- instead of File's Owner.whateverProperty as you have now.
_______________________________________________
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