如何打开只有一个窗口“首选项”?(How open only one window “Preferences”?)
我的应用程序有Preferences窗口。 我用这个代码打开它
- (IBAction)openPreferences:(id)sender { NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"]; [windowController window]; }如果按下命令,再次 - 一次又一次,新的“首选项”窗口将再次打开 - 一遍又一遍......
如何打开一个窗口? 谢谢!
My app have Preferences window. I open it using this code
- (IBAction)openPreferences:(id)sender { NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"]; [windowController window]; }If press command, again-again and again new Preferences window will be opened again-again and again...
How open only one window? Thanks!
最满意答案
使windowController成为你的AppDelegate的一个实例变量并且改变你的打开首选项
- (IBAction)openPreferences:(id)sender { if( windowController == nil ) windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"]; [windowController showWindow:sender]; }Make windowController a instance variable of your AppDelegate and change your open preferences to
- (IBAction)openPreferences:(id)sender { if( windowController == nil ) windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"]; [windowController showWindow:sender]; }更多推荐
发布评论