IPhone Development (3) --- iPhone application startup process

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.