• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
multi-window document best practices?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multi-window document best practices?


  • Subject: multi-window document best practices?
  • From: "email@hidden" <email@hidden>
  • Date: Sat, 12 May 2012 15:39:14 -0700

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 (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

  • Follow-Ups:
    • Re: multi-window document best practices?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: AwakeFromNib called twice for sheet
  • Next by Date: Re: multi-window document best practices?
  • Previous by thread: Re: mutableBytes Creates Autoreleased Objects
  • Next by thread: Re: multi-window document best practices?
  • Index(es):
    • Date
    • Thread