Start program start to view display:
Program startup first executes the main function-> Uiapplicationmain function:
- Program Startup (load frame, info file, resources, etc.)
- Executes the main function
- Initialize UIApplication Singleton Object
- Initializes the Appdelegate object and sets it as the proxy for the UIApplication object
- Then call UIApplication's Didfinishlaunchingwithoptions method to create the UIWindow object, set the Rootviewcontroller root controller, etc.
- It then establishes a main event loop that contains the uiapplication runloop to begin processing the event.
Executes the main function
The main function acts as the main entrance of the program, and the program starts to execute the main function automatically (the main function is a dead loop, which ensures that the program does not automatically close)
1 /* 2 * 1.1 program execution first executes the main function 3 */ 4 int Main (int argc, char argv[]) { 5 @autoreleasepool { 6 return U Iapplicationmain (argc, argv, Nil, Nsstringfromclass ([appdelegate class ])); 7 8 }
Initialize UIApplication Singleton Object
Initializes the Appdelegate object and sets it as the proxy for the UIApplication object
Create a UIApplication Singleton object and set the delegate object of the UIApplication (after entering the main function, the uiapplicationmain function is executed first)
So the launcher creates the application singleton object and sets the proxy appdelegate as the Application object
Look at the internal definition:
// argc, argv: direct transfer to Uiapplicationmain for related processing can // principalclassname: Specify application class name (symbol of APP), The class must be uiapplication (or subclass). If nil, the UIApplication class is used as the default value // delegateclassname: Specifies the application's proxy class, The class must adhere to the Uiapplicationdelegate protocol int uiapplicationmain (intchar argv[], NSString Principalclassname, NSString delegateclassname);
Call UIApplication's Didfinishlaunchingwithoptions method to create a UIWindow singleton object
After the program is started, the main Runloop (event loop) of the application is created, and the event is processed (the application:didfinishlaunchingwithoptions of the delegate object is called first after the program is finished: method Runloop Understanding, can refer to the article: reproduced from the "Chu-tian-shu iOS program and run Runloop" Application Agent Method analysis
1 //called when the application is finished (automatically called by the system)2-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions3 { 4 //creating UIWindow, setting up Rootviewcontrolle, and so on are all done here.5 6 //1. Create a UIWindow object7Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];8 9 //2. Create and set the UIWindow Rootviewcontroller (Root controller)TenCwlmainviewcontroller *mainviewcontroller =[Cwlmainviewcontroller alloc] init]; OneSelf.window.rootViewController =Mainviewcontroller; A - //3. display window - [Self.window makekeyandvisable]; the - returnYES; - } - //called when it is about to lose its active state (loses focus, cannot interact) +- (void) Applicationwillresignactive: (UIApplication *) Application - { + } A at //regain focus (ability to interact with users) -- (void) Applicationdidbecomeactive: (UIApplication *) Application - { - - } - in //called when the application enters the background -- (void) Applicationdidenterbackground: (UIApplication *) Application to { + //The application's data is typically stored in this method, as well as the state - } the * //called when the application is about to enter the foreground $- (void) Applicationwillenterforeground: (UIApplication *) ApplicationPanax Notoginseng { - //typically restores the application's data in this method, as well as the state the } + A //This method is called when the application is about to be destroyed the- (void) Applicationwillterminate: (UIApplication *) Application + { - //Note: This method cannot be called if the application is in a suspended state $ //alerts whether to close, save important information, etc. $ } - - //when the application receives a memory warning, it calls the the- (void) Applicationdidreceivememorywarning: (UIApplication *) Application - { Wuyi //here is the monitoring of the global memory warning method, all memory warnings are first received from here, and then passed to the various controllers for processing, generally in the method to release the unnecessary memory the}
multiple ways to create a controller
1. Create directly via Storyboard
2. Create directly
Cwlviewcontroller *CWL = [[Cwlviewcontroller alloc] init];
3. Create from Xib file
Cwlviewcontroller *CWL = [[Cwlviewcontroller alloc] Initwithnibname:@ "cwlviewcontroller" Bundle:nil]];
Multiple ways to create a view of a controller
After the controller is created, the creation of the controller's View,view is created in a number of cases, see:
Places to be aware of
1. The Loadview method priority of the controller is the highest
2. Because in the official document picture, has ignored the xib situation, if the storyboard is not set, the first judgment Xib file, the detailed effect is this.
Summary of "Learning Summary" IOS program running process, UIWindow, controller, UIView creation process