Mac OS X showWindow问题:NSWindow只出现一次
我有一个仅在状态栏中可见的 Mac OS X 程序,该程序必须显示首选项窗口。 我有这个 IBAction:
- (IBAction)showPreferences:(id)sender {
[self.preferencesWindowController showWindow:self];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
在 applicationDidFinish Lauching 中我有:
- (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
问题是:首选项窗口仅显示一次。当我关闭它时,它就不会再出现了。
可能是什么问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须更改窗口属性,以便它在关闭时不会被破坏。您可以在 Interface Builder 中执行此操作。
作为替代方案,我建议从
-showPreferences:
方法加载笔尖。在-applicationDidFinishLaunching:
方法中加载 nib 会减慢应用程序的启动时间,对用户或代码没有任何好处。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.