Re: [myWindowController window] returns null !
Re: [myWindowController window] returns null !
- Subject: Re: [myWindowController window] returns null !
- From: Louis Demers <email@hidden>
- Date: Thu, 24 Feb 2011 00:49:59 -0500
On 2011-02-24, at 00:22 , Kyle Sluder wrote:
> On Wed, Feb 23, 2011 at 8:55 PM, Louis Demers <email@hidden> wrote:
>> I temporarily set the File's Owner type to a NSWindowController class and connected the window to it. Got the same null value
>
> Rather than trash at the answer, it would be more helpful to learn the
> meaning behind your actions.
>
> If you set the File's Owner class to NSWindowController, but didn't
> change the owner you passed to -initWithWindowNibName:owner:, then of
> course it wouldn't work.
In the whirlwind of things I tried, I indeed forgot to to pass a different more appropriate parameter.
> The Class Identity of the File's Owner proxy
> in the nib is strictly informative; the actual class of File's Owner
> is the class of whatever you pass in as the owner.
>
> There's very little reason to use -initWithWindowNibName:owner:. It's
> much more typical to subclass NSWindowController and use
> -initWithWindowNibName: instead.
My app architecture may be unusual. It's the first time I use windowcontrollers and such.
My object is already subclassing something else and forcing it to subclass at some point NSWindowController would be awkward.
> But if you're going to use
> -initWithWindowNibName:owner:, you'll need some outlet on the owner
> object to which you connect your window. Then you can do something
> like this:
>
> @interface MyFilesOwner : NSObject
> @property(assign) IBOutlet NSWindow *windowOutlet; // Hooked up to window in nib
> @end
> // -=-=-=-
>
> MyFilesOwner *owner = [[MyFilesOwner alloc] init];
> NSWindowController *windowController = [[NSWindowController alloc]
> initWithWindowNibName:@"NibFile" owner:owner];
> [windowController setWindow:[owner windowOutlet]];
>
> //END
After Stephen's initial comment, I tried this approach (although not as well articulated)
It did not work for a small detail: after the initWithWindowNibName call, the xib file may be read and processed but unless showWindow is called, the window still null
so the working sequence I have is:
@interface PurgeSystem : NSObject
@property(assign) IBOutlet NSWindow *window; // Hooked up to window in nib
@end
windowControllerPurge_1 = [[NSWindowController alloc] initWithWindowNibName:@"PurgeSystem" owner: purgeSystem_1 ];
[windowControllerPurge_1 showWindow:purgeSystem_1]; // Commenting this line causes purgeSystem_1.window to be null.
[windowControllerPurge_1 setWindow: purgeSystem_1.window];
>
> But again, there's rarely any reason to prefer this to than merely
> subclassing NSWindowController and letting it be the File's Owner,
> which is the default behavior when you call -initWithWindowNibName:.
Thanks for pointing me in the right direction. I'll reflect on the app's structure to see how to apply that approach.
>
> --Kyle Sluder
Louis Demers eng.
www.obzerv.com
_______________________________________________
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