• 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
Re: multi-window document best practices?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi-window document best practices?


  • Subject: Re: multi-window document best practices?
  • From: Kyle Sluder <email@hidden>
  • Date: Sat, 12 May 2012 16:45:33 -0700

On May 12, 2012, at 3:39 PM, "email@hidden" <email@hidden> 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 (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: "email@hidden" <email@hidden>
References: 
 >multi-window document best practices? (From: "email@hidden" <email@hidden>)

  • Prev by Date: multi-window document best practices?
  • Next by Date: Re: multi-window document best practices?
  • Previous by thread: multi-window document best practices?
  • Next by thread: Re: multi-window document best practices?
  • Index(es):
    • Date
    • Thread