当窗户关闭时如何退出可可应用程序? [英] How to quit cocoa app when windows close?

查看:97
本文介绍了当窗户关闭时如何退出可可应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在点击左上角的红色按钮时退出Cocoa应用程序。





我发现页面说


首先是你要关闭的窗口是
连接到nib中的IBOutlet。对于这个例子,我将
窗口连接到名为mainWindow的插座。


我在xib文件中找到Windows,但是如何将它连接到nib中的IBOutlet?



或者,有没有办法退出可可应用程序点击红色按钮?



EDIT



我应该将代码放在自动生成的委托文件

解决方案

应用程序的代理有一个可选的方法,所有你需要做的是将其添加到实现。

   - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return YES;
}


I need to quit Cocoa App when I click the red button on upper left.

I found this page saying

So what you need to do first is have the window you want to close be connected to an IBOutlet in the nib. For this example i connected the window to an outlet named "mainWindow".

How can I do this? I found Windows in xib file, but how can I connect it to an IBOutlet in the nib?

Or, is there any way to quit the cocoa app clicking red button?

EDIT

I should have put the code in the automatically generated delegate file.

解决方案

There is an optional method for the application's delegate which will do this automatically. All you have to do is add this to the implementation. You don't need to create an outlet or anything.

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
    return YES;
}

这篇关于当窗户关闭时如何退出可可应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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