IPhone Development (2) iPhone application startup process

Source: Internet
Author: User

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:

 
 
  1. 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:

 
 
  1. <key>NSMainNibFile</key> 
  2.    <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.

 
 
  1. - (void)applicationDidFinishLaunching:(UIApplication *)application {  
  2.  
  3.     // Override point for customization after app launch  
  4.     [window addSubview:viewController.view];  
  5.     [window makeKeyAndVisible];  
  6. }  
  7.  
  8. - (void)dealloc {  
  9.     [viewController release];  
  10.     [window release];  
  11.     [super dealloc];  
 
 
  1. [Window addSubview: viewController. view]: XXXXXXViewController. xib, [window makeKeyAndVisible]

Yes.

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.

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

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.