The last time we saw the iPhone's entry function main, how does it start and initialize the Application? These are all implemented through UIApplicationMain.
The flowchart of its startup is roughly shown in:
1 int retVal = UIApplicationMain (argc, argv, nil, nil );
Use the preceding statement to create a UIApplication instance. At the same time, 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 name of the Application resource file (nib file, 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] indicates that XXXXXXViewController. xib and [window makeKeyAndVisible] are displayed in the window.
To sum up the above content, the iPhone application boot process is as follows:
1 main. m → MainWindow. xib → XXXXXXDelegate. m → XXXXXXViewController. m → XXXXXXViewController. xib
Or you can see the figure below to understand it.
Author: Yi Feiyang