防止窗户两次打开ߪ
我执行这些行来显示首选项窗口:
-(IBAction)showPreferences:(id)sender {
PreferencesWindowController *preferencesWindowController = [[PreferencesWindowController alloc] init];
NSNib *preferencesNib = [[NSNib alloc] initWithNibNamed:@"PreferencesWindow" bundle:nil];
[preferencesNib instantiateNibWithOwner:preferencesWindowController topLevelObjects:nil];
[NSApp activateIgnoringOtherApps:YES];
[[preferencesWindowController window] makeKeyAndOrderFront:nil];
[preferencesNib release];
}
但是当用户第二次单击首选项按钮(并且首选项窗口仍然打开)时,它将打开首选项窗口的另一个实例。
我应该如何在不使用控制变量的情况下防止这种情况发生?我应该将 PreferencesWindowController 编辑为单例吗?
I execute these lines to show the preferences window:
-(IBAction)showPreferences:(id)sender {
PreferencesWindowController *preferencesWindowController = [[PreferencesWindowController alloc] init];
NSNib *preferencesNib = [[NSNib alloc] initWithNibNamed:@"PreferencesWindow" bundle:nil];
[preferencesNib instantiateNibWithOwner:preferencesWindowController topLevelObjects:nil];
[NSApp activateIgnoringOtherApps:YES];
[[preferencesWindowController window] makeKeyAndOrderFront:nil];
[preferencesNib release];
}
But when the user clicks a second time on the preferences button (and the preferences window is still open) it will open up another instance of the preferences window.
How should I prevent this without hacking around with control variables? Should I edit my PreferencesWindowController to be a singleton?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的方法是在该操作所属的任何类中创建一个 PreferencesWindowController ivar:
My approach would be to make a PreferencesWindowController ivar in whatever class this action belongs to: