窗口关闭时停止模态(Cocoa) [英] Stopping modal when window is closed (Cocoa)

查看:272
本文介绍了窗口关闭时停止模态(Cocoa)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用此代码显示模态窗口:

I am currently displaying a modal window by using this code:

[[NSApplication sharedApplication] runModalForWindow:mainWindow];

但是,当我关闭此窗口时,其他窗口仍然处于非活动状态。当窗口使用red x关闭时,如何运行 stopModal 方法?

However, when I close this window, the other windows are still inactive. How do I run the stopModal method when the window is closed using the "red x"?

Michael

推荐答案

您可以为窗口创建委托让它响应

- (void)windowWillClose:(NSNotification *)通知

- (void)windowShouldClose: NSNotification *)notification 方法:

You can create a delegate for the window and have it respond to either the
-(void)windowWillClose:(NSNotification *)notification or the
- (void)windowShouldClose:(NSNotification *)notification methods like so:

- (void)windowWillClose:(NSNotification *)notification {
   [[NSApplication sharedApplication] stopModal];
}

查看 Mac开发人员中心:NSWindowDelegate协议参考

这篇关于窗口关闭时停止模态(Cocoa)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆