最后一个窗口关闭后退出应用程序
我想在最后一个主窗口关闭时关闭我的应用程序。由于以下原因,我无法使用 applicationShouldTerminateAfterLastWindowClosed:
:
1. 在显示主窗口之前,会显示一个确认窗口,当该窗口关闭时,应用程序不应退出。
2. 即使还有任何帮助窗口仍然打开,应用程序也应该在关闭主窗口后退出。
I want to close my application when the last main window closes. I cannot use applicationShouldTerminateAfterLastWindowClosed:
for the following reasons:
1. Before showing the main window, one confirmation window is displayed and when this window is closed, the application should not quit.
2. The application should quit after closing the main window even if there is any help window still open.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您仍然可以使用
applicationShouldTerminateAfterLastWindowClosed:
编写它以返回
NO
,直到您第一次显示主窗口的那一刻。从那时起让它返回YES
。NSPanel 的实例不计入打开的窗口。因此,如果您的帮助窗口是 NSPanel,这将起作用。
You may still use
applicationShouldTerminateAfterLastWindowClosed:
Write it to return
NO
until the moment you first show the main window. Make it returnYES
from then onwards.Instances of NSPanel don't count towards open windows. Thus this will work if your help window is a NSPanel.
您需要做的是将控制类设置为主窗口的委托,然后使用 NSNotificationCenter 添加一个带有 NSWindowWillCloseNotification 的观察者,其中 yourWindow 是对象。现在
,当主窗口关闭时,将调用 yourSelector 方法,因此在该方法中只需添加类似 exit(0); 的内容。
有关更多信息,请访问此处和查看窗口将关闭
What you need to do is set you controlling class as the delegate of your main window, and then using NSNotificationCenter add an observer with the NSWindowWillCloseNotification with yourWindow being the object. So like this
Now, the method yourSelector will be called when the main window is close, so in that method just have something like exit(0);
For more info go here and look at windowWillClose