UIApplicationMain详解
2012-10-17 19:45
387 查看
UIApplicationMain
This function is called in the mainentry 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 );ParametersargcThe 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
UIApplicationclass
or subclass. If you specify
nil,
UIApplicationis 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
nilif you load the delegate object from your application’s
main nib file.
Return ValueEven 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.DiscussionThis 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.plistfile specifies a main nib file to be loaded, by including the
NSMainNibFilekey
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.AvailabilityAvailable in iOS 2.0 and later.Related Sample CodeAQOfflineRenderTest
International
Mountains
SimpleNetworkStreams
SpeakHere
TableViewSuiteDeclared 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里的配置信息,不做其它任何事情
相关文章推荐
- UIApplicationMain详解
- UIApplicationMain详解
- UIAPPlicationMain() 函数详解 (一个应用程序的启动过程)
- UI基础:UI程序执行顺序(UIApplicationMain()函数),自定义视图
- 程序入口-UIApplicationMain
- Qt应用程序之Application Main Window详解
- IOS 中 main()函数中UIApplicationMain后面的代码不执行...
- iOS UIApplicationMain
- Coordinating Efforts Between View Controllers--UIApplicationMain 初始化的步骤
- UIApplicationMain、UIApplication 和 UIApplicationDelegate 协议的关系
- iOS UIApplication详解(单例、功能)
- UIApplicationsharedApplication的详解
- 【深入浅出IOS开发】UIApplication和UIApplicationDelegate详解
- iOS 程序入口UIApplicationMain
- iOS-UIApplicationMain以及UIApplication职责
- UIApplication sharedApplication详解
- UIApplicationMain(都做了什么)
- Error: You are creating QApplication before calling UIApplicationMain
- 【iOS】第01讲 UIView/UIViewController/UIApplication详解
- ios程序入口main及UIApplicationMain的研究