Hide/Show NSWindow?

Discussion in 'Mac Programming' started by Aranince, Jun 10, 2009.

  1. macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California
    #1
    I'm trying to create a preference window, but I am having a problem bringing the window "back to life." When I first launch the program and open the pref window, it opens fine. I then close the pref window and try to open it again and no window pops up. How do I get the window to come back up after I close it? Here is how I open it in the first place through the window controller:

    Code:
    -(void)showPreferenceWindow:(id)sender
    {
    	[NSApp activateIgnoringOtherApps:YES];
    	[[self window] center];
    	[[self window] makeKeyAndOrderFront:nil];	
    }
    
    ...and in the NSWindow subclass I just have

    Code:
    -(void)awakeFromNib
    {
    	[self setHidesOnDeactivate:NO];
    	[self setReleasedWhenClosed:NO];
    }
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Are you sure awakeFromNib is being called? Is [self window] non-nil? Don't assume things are what you think they are. Use the debugger or logging :)
     
  3. thread starter macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California
    #3
    awakeFromNib is being called...[self window] is nil(assuming I'm checking it correctly: [self window] == nil ) and the window controller's init method is being called and succeeding.

    My init method for the controller

    Code:
    -(id)init
    {
    	if((self = [super initWithWindowNibName:@"GHPreferences"]))
    	{
    
    	}
    	return self;
    }
    Why would self window be nil? It's nil the first time I open the pref window...which I find strange. Does [self window] not exist until I call makeKeyAndOrderFront?

    EDIT: I tried if([self isWindowLoaded] == NO) and the case is only true once.
     

Share This Page