IPhone applicationsOfStartup ProcessThis is the content to be introduced in this article. The last time we saw the iPhone's entry function main, how did it start the application and initialize it? These are all implemented through UIApplicationMain, let's seeStartup Process.
The flowchart of its startup is roughly shown in:
- int retVal = UIApplicationMain(argc, argv, nil, nil);
Use the preceding statement to create a UIApplication instance. View the Info. plist file of the application. This file records the basic information of some applications, such as the program name, version, and icon ). The file also contains the application resource file name nib, which is specified by the NSMainNibFile key ). As follows:
- <key>NSMainNibFile</key>
- <string>MainWindow</string>
The above means that when the application starts, the resource named MainWindow needs to be loaded from the nib file.
In fact, the nib file also refers to the MainWindow. xib file in the Resources Group in the project. We double-click the file and start Interface Builder to see the following figure:
Interface Builder has the following four projects:
The File's Owner object is actually an instance of UIApplication.
First Responder object. Each program has a first responder, such as a mouse event or a keyboard event, which is the corresponding object. For example, in a multi-document program, the menu response events are generally connected to the FirstResponder, because the main interface is generally in another nib. At this time, FirstResponder is the FileOwner of your primary nib.
Delegate object.
Window. Window displayed when the application is started.
After the application is started, you can customize your behavior, as shown in the following figure,
After the program is started, a message is sent to the applicationDidFinishLaunching method of UIApplicationDelegate. Here, we complete the initialization process. The following code.
- - (void)applicationDidFinishLaunching:(UIApplication *)application {
-
- // Override point for customization after app launch
- [window addSubview:viewController.view];
- [window makeKeyAndVisible];
- }
-
- - (void)dealloc {
- [viewController release];
- [window release];
- [super dealloc];
- }
- [Window addSubview: viewController. view]: XXXXXXViewController. xib, [window makeKeyAndVisible]
Yes.
To sum up the above content, the iPhone application boot process is as follows:
- main.m → MainWindow.xib → XXXXXXDelegate.m → XXXXXXViewController.m → XXXXXXViewController.xib
Or you can see the figure below to understand it.
Summary:IPhone applicationsOfStartup ProcessI hope this article will help you! For more information, see the following articles:
IPhone Development (advanced tutorial) Implementation of iPhone application project composition
IPhone Development (advanced 3) custom UIViewController case implementation
IPhone Development (Advanced 4) UIButton Case Study