UIApplicationMain详解

UIApplicationMain

This function is called in the main entry point to create the application object and the application delegate and set up the event cycle.

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);
Parameters
argc

The count of arguments in argv; this usually is the corresponding parameter to main.

argv

A variable list of arguments; this usually is the corresponding parameter to main.

principalClassName

The name of the UIApplication class or subclass. If you specify nilUIApplication is assumed.

delegateClassName

The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.

Return Value

Even though an integer return type is specified, this function never returns. When users exits an iPhone application by pressing the Home button, the application moves to the background.

Discussion

This function instantiates the application object from the principal class and and instantiates the delegate (if any) from the given class and sets the delegate for the application. It also sets up the main event loop, including the application’s run loop, and begins processing events. If the application’s Info.plist file specifies a main nib file to be loaded, by including the NSMainNibFile key and a valid nib file name for the value, this function loads that nib file.

Despite the declared return type, this function never returns. For more information on how this function behaves, see ““The Core Application Design”” in iOS Application Programming Guide.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIApplication.h

=================================邪恶的分割线=================================
对于UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName)的后面两个参数,一般都为nil,它代表的含义是:第三个参数默认为是@"UIApplication",这个参数必须是UIApplication或其子类的名字,它代表着当前iPhone程序本身,这个程序会去读info.plist文件获取配置信息,一个重要的信息是Main nib file base name(主nib文件)的值,一般为MainWindow(.xib),第四个参数为MainWindow.xib文件中遵循UIApplicationDelegate的类的类名,因为UIApplication定义了一个delegte变量,这个变量应该遵循UIApplicationDelegate,负责控制程序的运行,在主nib文件中,你应该创建一个继承于Object,并遵循UIApplicationDelegate的类,如果主nib文件没有这个类,你应该自定义一个这样的类,并将第四个参数改为这个类的类名,否则这个程序不知道如何进行运作,因为前三个参数代表应用程序本身,它除了把应用的事件循环启动起来,并读取info.plist里的配置信息,不做其它任何事情
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值