gpt4 book ai didi

cocoa - Mac OS X showWindow 问题 : NSWindow appears only once

转载 作者:行者123 更新时间:2023-12-03 16:20:39 24 4
gpt4 key购买 nike

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

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

在 applicationDidFinish 启动中我有:

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

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

可能是什么问题?

最佳答案

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

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

关于cocoa - Mac OS X showWindow 问题 : NSWindow appears only once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7324704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com