如何打开只有一个窗口“首选项”?(How open only one window “Preferences”?)

编程入门 行业动态 更新时间:2024-10-14 12:20:46
如何打开只有一个窗口“首选项”?(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]; }

更多推荐

本文发布于:2023-08-05 20:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:只有一个   首选   窗口   Preferences   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!