<span id="Label3"></p><p><p><span style="font-family:SimSun; font-size:18px">This section focuses on the life cycle of the application, the life cycle of the uiview, the exception handling process, and the loading process of the controller under the Uikit Framework.</span></p></p><p><p><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p><p><span style="font-family:SimSun; font-size:24px"><strong>Four object diagrams</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p><p><br></p></p><p><p><span style="font-family:SimSun; font-size:24px"><strong>Application life cycle</strong></span></p></p><p><p><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p><p><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p><p><span style="font-family:SimSun; font-size:18px">The above process is explained:</span></p></p><p><p><span style="font-family:SimSun; font-size:18px">1. The program starts execution, first enters the main function:</span></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">int main (int argc, char * argv[])</pre></pre><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br>2. Execute the Uiapplicationmain function:</span></span><p><p></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">return uiapplicationmain (argc, argv, nil, nsstringfromclass ([hkappdelegate class]));</pre></pre><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br>of the above function</span></span><p><p></p></p><p><p><span style="font-family:SimSun; font-size:18px">1th, the 2nd parameter is the system main function automatic processing parameter, does not do the Explanation.</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">The 3rd Parameter: The class name of the application symbol (can only pass uiapplication or its subclasses, if nil, the default is Uiapplication)</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">4th parameter: The class name of the UIApplication agent</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px"><br></span></p></p><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px">3. Once the Uiapplicationmain method has finished executing, the uiapplication is initialized and the message loop mechanism is opened using its proxy. </span></span><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br></span></span><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px">4. The Agent listener event is a run loop that listens to the listed events until the program Exits. </span></span><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br></span></span><span style="font-family:SimSun; font-size:24px"><span style="font-family:SimSun; font-size:24px"><strong>initialization process of the controller</strong></span></span><span style="font-family:SimSun; font-size:18px">During the <span style="font-family:SimSun; font-size:18px">application Life cycle, when the program is loaded,</span> the</span><pre name="code" class="objc"><pre name="code" class="objc">-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions</pre></pre><span style="font-size:18px"><span style="font-size:18px">method, You should complete the initialization of the root controller. </span></span><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br></span></span><p><p><span style="font-family:SimSun; font-size:18px">The approximate code is as Follows:</span></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { Self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; Override point for customization after application Launch. Self.window.backgroundColor = [uicolor redcolor]; Self.viewcontroller = [[lfviewcontroller alloc] initwithnibname:@ "lfviewcontroller" bundle:nil]; Display Controller's view [self.window addSubview:self.viewController.view]; Set the Window's root controller self.window.rootViewController = self.viewcontroller; [self.window makekeyandvisible]; Return YES;}</pre></pre><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br>1. Be sure to do a strong reference to the defined Viewcontroller property, or the Lfviewcontroller object will be destroyed when the Didfinishlaunchingwithoptions method is Finished. </span></span><p><p></p></p><p><p></p></p><pre name="code" class="objc"><pre name="code" class="objc">@property (strong, Nonatomic) Lfviewcontroller *viewcontroller;</pre></pre><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br>2. Controller Lfviewcontroller Load specific process description:</span></span><p><p></p></p><p><p></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">I. The view of the controller Lfviewcontroller is delayed-loaded</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">II. when a view is used, the Controller's Loadview method is invoked to load the view</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">Iii.loadview</span> <span style="font-family:SimSun; font-size:18px">Loading</span> <span style="font-family:SimSun; font-size:18px">View</span> <span style="font-family:SimSun; font-size:18px">the default procedure (</span> <span style="font-family:SimSun; font-size:18px">Uiviewcontroller</span> <span style="font-family:SimSun; font-size:18px">the default Implementation)</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">1> if Nibname has a value, the corresponding xib file is loaded to create the view</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">2> if Nibname has no value</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">1) first load the Lfview.xib file to create the view</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">2) load the Lfviewcontroller.xib file to create the view</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">3) If you do not find the Xib file described above, you will create a black view with the code</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:24px"><strong>Page life cycle</strong></span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px"><br></span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px">In the flow chart of the page life cycle, when viewdiddisappear, there is a possibility of low memory situation, will call the Viewdidunload method for memory warning processing work, the flowchart is as Follows:</span></p></p><p style="margin-top:0px; margin-bottom:0px"><p style="margin-top:0px; margin-bottom:0px"><span style="font-family:SimSun; font-size:18px"><br></span></p></p><span style="font-family:SimSun; font-size:18px"><span style="font-family:SimSun; font-size:18px"><br></span></span><br><p><p>Life cycle and loading process in iOS</p></p></span>
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