应用程序代理 - 可可 [英] Application Delegate - Cocoa

查看:102
本文介绍了应用程序代理 - 可可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的可可代理中加入一个applicationDidFinishLaunching:。我该怎么做呢?在iphone SDK的applicationDidFinishLaunching已经在应用程序委托,但是当我的mac应用程序,我注意到没有。

I want to incorporate an applicationDidFinishLaunching: into my cocoa delegate. How would I do this?? On the iphone SDK the applicationDidFinishLaunching is already in the application delegate, but when making my mac application I noticed that there were none.

最好的问候,

Kevin

推荐答案

在Xcode 3.2中,Mac应用程序模板还包含一个已经连接的应用程序委托,它有这样的方法。

As of Xcode 3.2, the Mac application template also comes with an application delegate, already connected, that has such a method.

在Xcode 3.2之前创建的项目中设置此项,为您的委托创建一个新类作为实例。我通常命名我的AppDelegate。您可以通过右键单击Classes组并选择添加文件,然后选择Cocoa NSObject子类文件模板。

To set this up in a project created before Xcode 3.2, create a new class for your delegate to be an instance of. I usually name mine "AppDelegate". You'll do this by right-clicking on the Classes group and choosing "Add File", then picking the Cocoa NSObject Subclass file template.

打开您刚刚创建的标题(AppDelegate.h)。给它任何你想要的实例变量。然后点击Go to Counterpart。这将带你到实现文件(AppDelegate.m)。在此处添加您的 applicationDidFinishLaunching:实例方法。与iPhone不同的是,这是一个通知处理程序方法,所以它需要一个NSNotification实例,而不是一个NSApplication实例。

Open the header you just created (AppDelegate.h). Give it any instance variables you want. Then hit Go to Counterpart. That takes you to the implementation file (AppDelegate.m). Add your applicationDidFinishLaunching: instance method here. Unlike on the iPhone, this is a notification-handler method, so it takes an NSNotification instance and not an NSApplication instance.

现在连接它。在资源组中,打开MainMenu.nib。将对象从库窗口拖动到顶级nib窗口(其中具有图标的窗口,例如文件的所有者和第一响应程序)。选择刚刚创建的对象,然后打开Identity检查器。将对象的类设置为AppDelegate,匹配您在Xcode中使用的名称。右键单击文件的所有者,然后从其委托插件拖动到新对象。

Now to hook it up. In the Resources group, open MainMenu.nib. Drag an Object from the Library window into the top-level nib window (the one with icons in it, such as File's Owner and First Responder). Select the object you just created and open the Identity inspector. Set the object's class to AppDelegate, matching the name you used in Xcode. Right-click on the File's Owner, and drag from its delegate outlet to your new object.

请向您的 applicationDidFinishLaunching:方法添加一个NSLog语句。点击Save All,然后Build和Go。切换回Xcode并打开调试器控制台。如果你做的一切正确,我没有忘记任何东西,你应该看到日志消息那里。

In Xcode, add an NSLog statement to your applicationDidFinishLaunching: method. Hit Save All, then Build and Go. Switch back to Xcode and open the Debugger Console. If you did everything right and I didn't forget anything, you should see the log message there.

这篇关于应用程序代理 - 可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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