DreamOfMirrors
DreamOfMirrors

Reputation: 2157

Mac OS X showWindow problem: NSWindow appears only once

I have a Mac OS X program visible only in status bar that must show a preferences window. I have this IBAction:

- (IBAction)showPreferences:(id)sender {
    [self.preferencesWindowController showWindow:self];
    [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}

In applicationDidFinish Lauching I have:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Load the app's preferences window (but does not display it)
    self.preferencesWindowController = [[PreferencesWindowController alloc] initWithWindowNibName:@"PreferencesWindowController"];

    [...]

}

The class header:

#import <Cocoa/Cocoa.h>
#import "AppPref.h"


@interface PreferencesWindowController : NSWindowController {
}

@end

The problem is: the preference window shows up only once. When I close it, it will never reappear anymore.

What may be the problem?

Upvotes: 3

Views: 2876

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213228

You have to change the window properties so that it is not destroyed when it is closed. You can do this in Interface Builder.

As an alternative, I recommend loading the nib from the -showPreferences: method. Loading the nib in the -applicationDidFinishLaunching: method will slow down your application launch time with no benefit to the user or your code.

Upvotes: 2

Related Questions