-
First, the function creates the main application object (step 3 in the flowchart). If you nil are specify as the third argument UIApplicationMain() to (the default), it would create an instance of of ' this UIApplication step. This was usually what do you want. However, if you need to subclass UIApplication (for example, to override it event handling in sendEvent: ), you have the to pass a string WI Th the name of your subclass to UIApplicationMain() .
-
The function then looks on its fourth argument. If It is non-nil, it interprets it as the name of the that class for the application delegate, instantiates a object of this C Lass and assigns it as the Application object ' s delegate . The default for the fourth argument are nil , though, which signifies that the app delegate would be created in the main NI B file.
-
Next, UIApplicationMain() loads and parses your app ' s Info.plist (step 4). If it contains a key named "Main nib File base name" ( NSMainNibFile ), the function would also load the nib file specified there (St EP 5).
-
By default, the main NIB file is called mainwindow.nib . It contains at least a object representing the application delegate, connected to the File ' Owner ' s delegate< /code> outlet (step 6), and a UIWindow object that'll be used as the app's main window, conn ected to an outlet of the app delegate. If you used a view-controller-based app template, the NIB file would also contain your app ' s root View controller and Possi Bly one or more view child controllers.
It's worth mentioning that's the only step where the Uikit-based app templates (window-based, view-based, Navigatio n-based, tab-based, etc.) differ significantly from each of the other. If you started off with a view-based apps and later want to introduce a navigation controller, there are no need to start a New project:simply Replace the root view controller in the main NIB file and adjust one or both lines of code in the app D Elegate. I noticed that many newbies to the IOS platform struggle with this problem and assume a huge difference between the differ ENT project templates. There isn ' t.
-
Now, UIApplicationMain() creates the application's run loop that's used by the UIApplication instance to process events such as touches or netwo RK Events (step 7). The run loop is basically an infinite loop, causes to UIApplicationMain() never return.
-
Before the Application object processes the first event, it finally sends the well-known application:didFinishLaunchingWithOptions: message to its delegate, GIV ing us the chance to does our own setup (step 8). The least we have an to does here are put our main window on the screens by sending it a makeKeyAndVisible message.
This is the original part of my excerpt, English good can see, the following talk about their understanding
1 main function
int Main (intChar * argv[]) { NSLog (@ "===%s", argv[0]); @autoreleasepool { /// function prototype: // int Uiapplicationmain ( int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname); return class ])); }}
The code in this is usually the same. The first is an auto-release pool, which guarantees the end of memory release, here is the parameter description:
ARGC, argv: is the parameter of the label C, ARGC is the number of elements in the argv array. ARGV generally have an element argv[0] that is the path of the currently executable program. (in addition, under the Linux system we open a program through the terminal can pass parameters to it, specifically no longer expanded.) If the automatic ignoring inside the parentheses);
2 Uiapplicationmain
1) Create UIApplication objects according to the parameters passed in;
2) Creates a UIApplication delegate object based on the arguments passed in and assigns the delegate object to the delegate property in the UIApplication object.
3) Turn on a message loop
Specific Description:
A uiapplicationmain function is executed in the main function.
int uiapplicationmain (int argc, char *argv[], nsstring *principalclassname, NSString *delegateclassname);
ARGC, argv: direct transfer to Uiapplicationmain for related processing can be
Principalclassname: Specifies the application class name (symbol of the app), which must be uiapplication (or subclass). If nil, then use the UIApplication class as the default value, It is a singleton, representing a process, is also the first object created by the program, using the UIApplication object, can do some application-level operations;
Delegateclassname: Specifies the application's proxy class, which must comply with the Uiapplicationdelegate protocol
The Uiapplicationmain function creates a UIApplication object based on Principalclassname and creates a delegate object from Delegateclassname. and assigns the delegate object to the delegate property in the UIApplication object
The application's main Runloop (the event loop) is then created, and the event is processed (the application:didfinishlaunchingwithoptions of the delegate object is called first after the program is completed: method)
The Uiapplicationmain function returns when the program exits normally
The following are divided into storyboard start and no storyboard boot
# #有storyboard # #
3 load Storyboard According to Info.plist
1) Creating a Uiwindow,uiwindow is a special kind of uiview that usually has only one UIWindow in an app (note that usually, there are other, such as pop-up keyboards). The main window is set as the primary window, with only one at the same time, which can be obtained by [UIApplication Sharedapplication].keywindow.
2) Create and set the UIWindow Rootviewcontroller.
3) Display window
Specific Description:
Get the most important storyboard file name according to Info.plist, load the main storyboard ( with storyboard)
-create uiwindow
- Creates and sets the Rootviewcontroller of the UIWindow (the controller that the arrow points to in the storyboard)
-Displays the window
There is storyboard: Official document: iosx/uikit/ Viewcontroller p C for iOS
the main Storyboard initializes Your App's User interface
The main Storyboard is de Fined in the app's Information property list file. If A main storyboard is declared in this file and then when your app launches, IOS performs the following steps: /p>
- It instantiates a window for you.
- It loads the main storyboard and instantiates its initial view controller.
- It assigns the new view Controller to the window's Rootviewcontroller property and then makes the window visible on the SC Reen.
Translation:
-
The main story panel initializes the application's user interface
The Information property list file for the application that is defined in the main story panel. If a major story is declared in this Info.plist file (main), then when your app launches, iOS performs the following steps:
1. It instantiates a window for you.
2. It loads (arrows pointing) the main story panel and instantiates it as the initial view controller.
3. It gives the new View Controller window Rootviewcontroller and will display the contents of this window on the screen.
# #没有storyboard # #
3 delegate object starts processing (listening) system events (no storyboard)
1) When the program is started, the agent's application:didfinishlaunchingwithoptions is called: method
2) Create Uiwindow:window in Application:didfinishlaunchingwithoptions:
3) Create and set the UIWindow Rootviewcontroller
4) Display and set window as main windows: [Window makekeyandvisible]; Then Self.window = window; prevent it from being released.
iOS program startup process