iOS Development UI Chapter-uitabbarcontroller lifecycle (built with Storyoard)

Source: Internet
Author: User
<span id="Label3"></p><strong><strong>iOS Development UI Chapter-uitabbarcontroller lifecycle (built with Storyoard)</strong></strong>first, Uitabbarcontroller in the Storyoard to build 1. Create a new project, remove the default controller from storyboard, and drag UITab Bar controller. 2. Create the Viewcontroller and add to the UITab Bar controller (wired).<span style="color: #ff0000;"><span style="color: #ff0000;">Note: The order of the lines is the order of the future display, shown in front of the first line of VIEW. </span></span><span><span>tip: The Controller interface corresponds to the Tabbarbutton and the picture shows what content is determined by its controller. </span></span>3. Set the Uitabbar and other information of the Sub-controller. 4. Running effect two, Uitabbarcontroller life cycle demonstration Idea: new three controller class to manage the controller separately, rewrite internal life cycle method can understand Uitabbarcontroller internal management Mechanism. Analysis Code:<span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><span style="color: #008080;">1<span style="color: #008000;">//<span style="color: #008080;">2<span style="color: #008000;">//<span style="color: #008000;">Yybaseviewcontroller.m<span style="color: #008080;">3<span style="color: #008000;">//<span style="color: #008000;">02-uitabbarcontroller<span style="color: #008080;">4<span style="color: #008000;">//<span style="color: #008080;">5<span style="color: #008000;">//<span style="color: #008000;">Created by Hole Medical has on 14-6-8.<span style="color: #008080;">6<span style="color: #008000;">//<span style="color: #008000;">Copyright (c) 2014 Itcast. All Rights Reserved.<span style="color: #008080;">7<span style="color: #008000;">//<span style="color: #008080;">8<span style="color: #008080;">9<span style="color: #0000ff;">#import<span style="color: #800000;">"<span style="color: #800000;">YYbaseViewController.h<span style="color: #800000;">"<span style="color: #008080;">10<span style="color: #008080;">11<span style="color: #0000ff;">@interface<span style="color: #000000;">Yybaseviewcontroller ()<span style="color: #008080;">12<span style="color: #008080;">13<span style="color: #0000ff;">@end<span style="color: #008080;">14<span style="color: #008080;">15<span style="color: #0000ff;">@implementation<span style="color: #000000;">Yybaseviewcontroller<span style="color: #008080;">16<span style="color: #008080;">17<span style="color: #008000;">//<span style="color: #008000;">When the view of the controller is loaded, it is called<span style="color: #008080;">18-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewdidload<span style="color: #008080;">19<span style="color: #000000;">{<span style="color: #008080;">20<span style="color: #000000;">[super viewdidload];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-controller View Load Complete<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">22<span style="color: #000000;">}<span style="color: #008080;">23<span style="color: #008080;">24<span style="color: #008000;">//<span style="color: #008000;">Called when the controller is about to be displayed<span style="color: #008080;">25-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewwillappear: (BOOL) Animated<span style="color: #008080;">26<span style="color: #000000;">{<span style="color: #008080;">27<span style="color: #000000;">[super viewwillappear:yes];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-controller is about to be displayed<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">29<span style="color: #000000;">}<span style="color: #008080;">30<span style="color: #008080;">31<span style="color: #008000;">//<span style="color: #008000;">Called when the controller is fully displayed<span style="color: #008080;">32-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewdidappear: (BOOL) Animated<span style="color: #008080;">33<span style="color: #000000;">{<span style="color: #008080;">34<span style="color: #000000;">[super viewdidappear:animated];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-controller Full Display<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">36<span style="color: #000000;">}<span style="color: #008080;">37<span style="color: #008080;">38<span style="color: #008000;">//<span style="color: #008000;">Call when the controller is about to disappear<span style="color: #008080;">39-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewwilldisappear: (BOOL) Animated<span style="color: #008080;">40<span style="color: #000000;">{<span style="color: #008080;">41<span style="color: #000000;">[super viewwilldisappear:animated];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-controller is about to disappear<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">43<span style="color: #000000;">}<span style="color: #008080;">44<span style="color: #008000;">//<span style="color: #008000;">Call when the controller disappears completely<span style="color: #008080;">45-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewdiddisappear: (BOOL) Animated<span style="color: #008080;">46<span style="color: #000000;">{<span style="color: #008080;">47<span style="color: #000000;">[super viewdiddisappear:animated];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-controller completely disappears<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">49<span style="color: #000000;">}<span style="color: #008080;">50<span style="color: #008080;">51-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewwillunload<span style="color: #008080;">52<span style="color: #000000;">{<span style="color: #008080;">53<span style="color: #000000;">[super viewwillunload];<span style="color: #008080;">NSLog (<span style="color: #800000;">@"<span style="color: #800000;">%@-view is about to be destroyed<span style="color: #800000;">", [self<span style="color: #0000ff;">Class<span style="color: #000000;">]);<span style="color: #008080;">55<span style="color: #000000;">}<span style="color: #008080;">56<span style="color: #008080;">57-(<span style="color: #0000ff;">void<span style="color: #000000;">) Viewdidunload<span style="color: #008080;">58<span style="color: #000000;">{<span style="color: #008080;">59<span style="color: #000000;">[super viewdidunload];<span style="color: #008080;">NSLog (<span style="color: #800000;"><span style="color: #800000;">@ "<span style=" color: #800000; ">%@-view is completely destroyed <span style=" color: #800000; ">", [ Self <span style="color: #0000ff;">class<span style="color: #008080;" ]); <span>61 <span style="color: #000000;">}<span style="color: #008080;">62 <span style=" Color: #008080; ">63-(<span style="color: #0000ff;">void<span style="color: #008080;" ] dealloc<span>64 Span style= "color: #000000;" >{<span style="color: #008080;">65 NSLog (<span style="color: #800000;">@ "<span style=" color: #800000; ">%@<span style="color: #800000;"> ", [self <span style=" color: #0000ff; ">class<span style="color: #008080;" ]); <span>66 <span style="color: #000000;">}<span style="color: #008080;">67 <span style=" Color: #008080; ">68 <span style="color: #0000ff;"> @end </span> </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span>(1) Run the program, print output as:<span><span>Note: When the three sub-controllers are added to Uitabbarcontroller to manage, when the program starts it will only load the view of the first added controller. </span></span>(2) Click the contact button to switch to the second interface. Print output As:<span>Note: first view is removed and the <span>new view is added, but the first view is not Destroyed. </span></span>(3) Click the message screen again to print as Follows:<span><span>note: The first switch to the message interface, the one controller will be displayed directly, no load proof (2) The first view is removed and not destroyed (because its controller is still there, there is a strong reference to it), and two of the view has not been destroyed after the Removal. No matter how you switch, the controller and view will not be Destroyed. </span></span>Uinavigationcontroller and Uitabbarcontroller are managed by a stack, one through an ordinary array.<span><span>Supplementary Note: The actual height of Uitabbar in Uitabbarcontroller is.</span></span>Print the Uitabbar frame for viewing in the following method of Application.<span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><pre>-(<span style="color: #0000ff;">void) applicationdidbecomeactive: (uiapplication *<span style="color: #000000;">) application{ <span style="color: #008000;">//<span style="color: #008000;"> Restart any tasks that were Paused (or not yet started) and the application was Inactive. If the application is previously in the background, optionally refresh the user interface. Uitabbarcontroller *tb= (uitabbarcontroller*<span style="color: #000000;">) self.window.rootViewController; NSLog (<span style="color: #800000;">@ "<span style="color: #800000;">%@<span style="color: #800000;">"<span style="color: #000000;">, Nsstringfromcgrect (tb.tabBar.frame));}</span> </span> </span> </span> </span> </span> </span> </span> </span></pre></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>Printing results Are:</p></p><p><p></p></p><p><p>iOS Development UI Chapter-uitabbarcontroller lifecycle (built with Storyoard)</p></p></span>

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.