如何更改应用程序委托类? [英] How to change the Application Delegate class?
问题描述
在每个iOS应用程序中都有一个App Delegate类,这意味着应用程序中的一个类必须实现应用程序事件的委托方法,例如 didFinishLaunching:
等.通常,类名包含"AppDelegate".
In every iOS app there is an App Delegate class, meaning one of the classes in the app has to implement the delegate methods for the application events such as didFinishLaunching:
and so forth. Usually the class name contains "AppDelegate".
App Delegate类是iOS上 UIApplicationDelegate
或Mac上 NSApplicationDelegate
的子类.
The App Delegate class is a subclass of UIApplicationDelegate
on iOS or NSApplicationDelegate
on the Mac.
class AppDelegate: UIApplicationDelegate {
}
比方说,我想在与为我创建和命名的原始Xcode不同的类中实现App Delegate方法.我该怎么办?
Let's say I want to implement the App Delegate methods in a different class than the original one Xcode created and named for me. How can I do that?
推荐答案
您可以通过修改 main.m 中存在的 UIApplicationMain
函数的参数来进行相同的操作文件:
You can do the same by modifying the parameters to the UIApplicationMain
function present in the main.m file:
UIApplicationMain(argc,argv,nil,nil);
最后一个参数采用实现 UIApplicationDelegate 协议的类的名称.
The last parameter takes the name of the class which is implementing the UIApplicationDelegate protocol.
因此,默认实现如下所示:
So the default implementation looks something like:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
修改后,将类似于:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([< Your class name will go here > class]));
[pool release];
return retVal;
这篇关于如何更改应用程序委托类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!