NSWindowController opens once

  • Hi there,
    I'm getting a little flummoxed by the mysterious behaviour of some of
    my project's window controllers! I have my main appcontroller with a
    function for opening my Preferences window:

    -(IBAction)showPreferencePanel:(id)sender
    {
    if(!preferenceController) {
      preferenceController = [[PreferenceController alloc] init];
    }
    [preferenceController showWindow:self];
    }

    All cool, and in my PreferenceController, the following code to
    initialize the window:

    -(id)init
    {
    self = [super initWithWindowNibName:@"preferences"];
    theWindow = [self window];
    [theWindow makeKeyAndOrderFront:self];
    return self;
    }

    All right, so I have two problems:

    1. Preferences opens fine the first time. But when you try to open it
    again, nothing happens. The menu item flashes when you hit Command-,,
    but that's it.

    2. Despite sending a makeKeyAndOrderFront: method call, the window
    comes up inactive.

    What am I missing here?

    Thanks!
    Aaron.

    --
    Aaron Vegh, Principal
    Innoveghtive Inc.
    P: (647) 477-2690
    C: (905) 924-1220
    www.innoveghtive.com
    www.website-in-a-day.com
  • On Dec 16, 2007, at 12:02 PM, Aaron Vegh wrote:

    > -(id)init
    > {
    > self = [super initWithWindowNibName:@"preferences"];
    > theWindow = [self window];
    > [theWindow makeKeyAndOrderFront:self];
    > return self;
    > }

    It seems that you have a "theWindow" instance variable in your window
    controller subclass? That shouldn't be necessary, as
    NSWindowController already has such an instance variable. Note that
    you need to hook this outlet up in IB though!

    I wouldn't call "-makeKeyAndOrderFront:" from the init method. Note
    that you also already take care about that with your call to "-
    showWindow:" in your "-showPreferencePanel:" method.

    > 1. Preferences opens fine the first time. But when you try to open it
    > again, nothing happens. The menu item flashes when you hit Command-,,
    > but that's it.

    Perhaps you've set the window to "release when closed" in the nib file?

    j o a r
  • > It seems that you have a "theWindow" instance variable in your window
    > controller subclass? That shouldn't be necessary, as
    > NSWindowController already has such an instance variable. Note that
    > you need to hook this outlet up in IB though!

    ... and that was what I was missing. I connected the window instance
    to the File's Owner in my window controller's nib, and removed the
    "theWindow" var. Took care of both problems!

    That's the thing with Cocoa, isn't it? Sometimes you want to overthink
    and overdo behaviour in an application, but the framework's got your
    back. I dig it.

    Cheers!
    Aaron.
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today