3

我有一个仅在必须显示首选项窗口的状态栏中可见的 Mac OS X 程序。我有这个 IBAction:

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

在 applicationDidFinish Launching 我有:

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

    [...]

}

类头:

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


@interface PreferencesWindowController : NSWindowController {
}

@end

问题是:首选项窗口只显示一次。当我关闭它时,它再也不会出现了。

可能是什么问题?

4

1 回答 1

2

您必须更改窗口属性,使其在关闭时不会被破坏。您可以在 Interface Builder 中执行此操作。

作为替代方案,我建议从-showPreferences:方法中加载 nib。在方法中加载 nib-applicationDidFinishLaunching:会减慢您的应用程序启动时间,而对用户或您的代码没有任何好处。

于 2011-09-06T19:00:37.647 回答