如何更改App-Delegate类

Ode*_*gev 7 iphone xcode ios

在每个iOS应用程序上都有一个app-delegate类,这意味着应用程序中的一个类必须实现应用程序事件的委托方法,例如didFinishLaunching等(通常类名称包含"appDelegate").

我的问题是:假设我想在不同的类中实现app-delegate方法,而不是原来的xcode为我决定的.我怎样才能做到这一点?

Amr*_*mar 9

您可以通过修改参数来完成相同的操作

UIApplicationMain(argc,argv,nil,nil);
存在于main.m文件中.最后一个参数采用实现UIApplicationDelegate协议的类的名称.
所以默认实现看起来像

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;