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?

By experimenting, I have discovered that inside -[NSWindowController window], 
there is some magic happening. If owner->window is pointing at the window being 
loaded, the window controller's window member gets properly set. Otherwise, it 
does not.

That seems wrong, or at least very unexpected. And undocumented. 

Can anyone explain what's going on and why? And what the "right" way to do 
multiple windowed docs is?

_murat 
_______________________________________________

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