简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM