主文件中的标准参数 [英] Standard arguments in main file

查看:17
本文介绍了主文件中的标准参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主文件中的标准参数是什么.我想我在主文件中设置了错误的标准参数,需要将它们改回来.我认为问题在于 UIApplicationMain 参数中的 nil 和 nil.

What are the standard arguments in the main file. I think I have set the wrong standard arguments in the main file, and need to change them back. I think the problem is the nil and nil in the UIApplicationMain arguments.

这是我的代码:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

错误代码:

Attaching to process 1420.
2011-09-02 14:33:04.440 HypnoTime[1420:207] *** Assertion failure in           UIApplicationMain(), /SourceCache/UIKit_Sim/UIKit-1448.89/UIApplication.m:1359
2011-09-02 14:33:04.588 HypnoTime[1420:207] *** Terminating app due to uncaught      exception 'NSInternalInconsistencyException', reason: 'Unable to instantiate the      UIApplication delegate instance. No class named AppDelegate is loaded.'
 *** Call stack at first throw:
 (
     0   CoreFoundation                      0x00dc15a9 __exceptionPreprocess + 185
     1   libobjc.A.dylib                     0x00f15313 objc_exception_throw + 44
     2   CoreFoundation                      0x00d79ef8 +[NSException      raise:format:arguments:] + 136
     3   Foundation                          0x00816341 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
     4   UIKit                               0x00021bcd UIApplicationMain + 962
     5   HypnoTime                           0x000027cf main + 127
     6   HypnoTime                           0x00002745 start + 53
     7   ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Current language:  auto; currently objective-c
(gdb) 

推荐答案

UIApplicationMain 的最后一个参数是 UIApplicationDelegate 子类的名称.如果您以编程方式创建您的应用程序,而没有任何 nib 文件,则这是必需的.

Last argument of UIApplicationMain is the name of your UIApplicationDelegate subclass. It's required if you are creating your app programmatically, without any nib files.

int retval = UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegate class]));

您需要 #import "YourAppDelegate.h" 才能以这种方式工作,或者您可以像 Voloda2 建议的那样硬编码名称.

You need to #import "YourAppDelegate.h" for it to work that way, or you can just hardcode the name like Voloda2 suggested.

使用这种方式的好处是,如果您更改应用程序委托类名称,您将立即收到编译器警告,而如果它是硬编码的,它将构建 &运行没有警告,但崩溃.

Advantage to using this way is if your change your app delegate class name, you will get a compiler warning right away, while if it's hardcoded, it will build & run without warnings, but crash.

这篇关于主文件中的标准参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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