主文件中的标准参数是什么.我想我在主文件中设置了错误的标准参数,需要更改它们.我认为问题是UIApplicationMain参数中的nil和nil.
这是我的代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
错误代码:
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)
Run Code Online (Sandbox Code Playgroud)
UIApplicationMain的最后一个参数是您的UIApplicationDelegate子类的名称.如果您以编程方式创建应用程序,而不使用任何nib文件,则需要它.
int retval = UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegate class]));
Run Code Online (Sandbox Code Playgroud)
您需要以#import "YourAppDelegate.h"这种方式工作,或者您可以像Voloda2建议的那样对该名称进行硬编码.
使用这种方式的好处是,如果您更改您的app委托类名称,您将立即收到编译器警告,而如果它是硬编码的,它将构建并运行而不会发出警告,但会崩溃.
| 归档时间: |
|
| 查看次数: |
4751 次 |
| 最近记录: |