On May 12, 2012, at 3:39 PM, "mlist0...@gmail.com" <mlist0...@gmail.com> wrote:

> I've have come across some surprising behavior when trying to implement a 
> document with two windows, each loaded from its own nib. 
> 
> In my NSDocument subclass, I have 
> 
> - (void) makeWindowControllers
> {
>    NSWindowController* wc1 = [[[NSWindowController alloc] 
> initWithWindowNibName:@"MNKDocument" owner:self]autorelease];
>    [self addWindowController:wc1];
>    [wc1 window]; // loads nib the first time it's called.
> 
>    NSLog(@"wc1->window = %@", [wc1 window]);
> 
> 
>    NSWindowController* wc2 = [[[NSWindowController alloc] 
> initWithWindowNibName:@"MNKDocumentSecondWindow" owner:self] autorelease];
>    [self addWindowController:wc2];
>    [wc2 window]; // loads nib the first time it's called.
> 
>    NSLog(@"wc2->window = %@", [wc2 window]);
> }
> 
> 
> wc1 is loading the default nib provided by Xcode's document-based app 
> template. wc2 is loading a nib I made by simply duplicating the default nib.
> 
> The "File's Owner" in both nibs is my document subclass. In the first nib 
> file, the "File's Owner" has its "window" outlet connected to the window in 
> the nib. Pretty vanilla.
> 
> In the second nib, the File Owner's "window" outlet is disconnected. The 
> window in the second nib is connected to the file owner's "secondWindow" 
> outlet.
> 
> After the nibs are loaded, I can see in the debugger that wc1->window points 
> to the correct window, but wc2->window is nil. WTF?

Document-as-File's-Owner only makes sense if you aren't overriding 
-makeWindowControllers.

Just make the window controllers themselves the File's Owner of the nib by 
passing 'nil' for the owner argument to the initializer in your override of 
-makeWindowControllers. Yes, that means a bit more refactoring might be 
necessary in your nibs.

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to