gpt4 book ai didi

objective-c - 如何在 Cocoa/Objective-C 中使用应用程序委托(delegate)?

转载 作者:行者123 更新时间:2023-12-03 17:36:22 26 4
gpt4 key购买 nike

我问了一个关于 quitting an App when windows close 的问题,答案是使用委托(delegate):

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

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

It definitely works, but you may have put the code in the wrong place. Make sure it's in your application's delegate.

我不确定如何将 applicationShouldTerminateAfterLastWindowClosed 放入应用程序的委托(delegate)中?

最佳答案

您的 xcode 项目应该在创建项目时创建了一个应用程序委托(delegate)类。要在委托(delegate)中实现此功能,您唯一需要做的就是将该方法添加到委托(delegate) .m 文件中(您无需担心 .h 文件,因为该方法已声明为应用程序委托(delegate)协议(protocol)的一部分) )。

关于objective-c - 如何在 Cocoa/Objective-C 中使用应用程序委托(delegate)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5274590/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com