PDA

View Full Version : Hide/Show NSWindow?




Aranince
Jun 11, 2009, 12:12 AM
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:


-(void)showPreferenceWindow:(id)sender
{
[NSApp activateIgnoringOtherApps:YES];
[[self window] center];
[[self window] makeKeyAndOrderFront:nil];
}


...and in the NSWindow subclass I just have


-(void)awakeFromNib
{
[self setHidesOnDeactivate:NO];
[self setReleasedWhenClosed:NO];
}



kainjow
Jun 11, 2009, 12:40 AM
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 :)

Aranince
Jun 11, 2009, 06:16 PM
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

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