您的位置:首页 > 移动开发

UIApplicationMain详解

2011-08-22 13:30 288 查看


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
argcThe count of arguments in argv; this usually is the corresponding parameter to
main
.
argvA variable list of arguments; this usually is the corresponding parameter to
main
.
principalClassNameThe name of the
UIApplication
class
or subclass. If you specify
nil
,
UIApplication
is assumed.
delegateClassNameThe 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.
Related Sample Code
AQOfflineRenderTestInternational
MountainsSimpleNetworkStreamsSpeakHereTableViewSuite
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里的配置信息,不做其它任何事情。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: