• 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: Easy Question re NSWindowController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easy Question re NSWindowController


  • Subject: Re: Easy Question re NSWindowController
  • From: Steven Degutis <email@hidden>
  • Date: Sat, 5 Sep 2009 08:50:54 -0500

Generally, all root objects such as NSWindowController that are placed in a
NIB (and aren't the File's Owner) will have +alloc and -init called to
initialize them. I've not heard of NSWindowController having
-initWithWindow: called instead when inside a NIB in this way, but then
again, I've also not ever had an NSWindowController and NSWindow in a NIB
that isn't their own.
My suggestion is this: place the NSWindowController in the main window's NIB
as a secondary object (ie, not File's Owner) and connect your button to its
-showWindow: method. Don't forget to make sure this NSWindowController is
subclassed! Now, create another NIB with a window, and make File's Owner the
subclass of your NSWindowController. Connect the window outlet in *this*
nib. Then, inside your subclass of NSWindowController, override -init to
call super's initWithWindowNibName: and pass the name of this second NIB
file you've just created. That's how I do it.

--
Steven Degutis
http://www.thoughtfultree.com/
http://www.degutis.org/


On Sat, Sep 5, 2009 at 7:42 AM, Brad Gibbs <email@hidden> wrote:

> I've done some testing, but I just can't make this work...
>
> I have an NSWindowController that manages a pop-up window and a button in
> the main window that launches the pop-up window when it's pressed.  I need
> to pass a managedObjectContext to the window controller.
>
> If I create the NSWindowController programmatically with a custom
> initializer:
>
>        NSWindowController *myWindowController = [[NSWindowController alloc]
> initWithWindowNibName:@"MyWindow" moc:self.managedObjectContext];
>
> everything works fine.  I can also pass the managedObejctContext separately
> without breaking anything.
>
> But, things fall apart when I try to add the window controller to the main
> window's nib.  Once I add an object for the window controller in the main
> window's nib and set its class to NSWindowController, the app uses
> NSWindowController's designated initializer, initWithWindow to initialize
> the window controller.
>
> By default, NSWindowController contains an outlet for its window.  If I
> connect the NSWindowController's window outlet to the pop up window and add
> an NSLog to the initWithWindow method asking for NSWindowController's
> self.window, it comes back null and the window doesn't load.
>
> It seems like the connection in the pop up window's nib file from File's
> Owner (the NSWindowController) outlet to the window is not being honored.
>  Even if I create another outlet (oWindow), connect it to the window
> controller and try to set it in initWithWindow with:
>
> - (id)initWithWindow:(NSWindow *)window {
>        if (self == [super initWithWindow:self.oWindow]) {
>                //NSLog(@"Window is %@", self.window);
>                NSLog(@"MOC is %@", self.mMainManagedObjectContext);
>                self.window.title = @"New Account";
>        }
>
>        return self;
> }
>
>  it fails.
>
> How can I make this work?
>
>
> Thanks.
>
> Brad
> _______________________________________________
>
> 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
>
_______________________________________________

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

References: 
 >Easy Question re NSWindowController (From: Brad Gibbs <email@hidden>)

  • Prev by Date: Easy Question re NSWindowController
  • Next by Date: Re: Having problem with fetch request in NSDocument based application
  • Previous by thread: Easy Question re NSWindowController
  • Next by thread: Re: Easy Question re NSWindowController
  • Index(es):
    • Date
    • Thread