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

Source: Internet
Author: User

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).Note: The order of the lines is the order of the future display, shown in front of the first line of view. Tip: The Controller interface corresponds to the Tabbarbutton and the picture shows what content is determined by its controller. 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:
1//2//Yybaseviewcontroller.m3//02-uitabbarcontroller4//5//Created by Hole Medical has on 14-6-8.6//Copyright (c) 2014 itcast. All rights reserved.7//89#import"YYbaseViewController.h"1011@interfaceYybaseviewcontroller ()1213@end1415@implementationYybaseviewcontroller1617//When the view of the controller is loaded, it is called18-(void) Viewdidload19{20[Super Viewdidload];NSLog (@"%@-Controller View load complete", [SelfClass]);22}2324//Called when the controller is about to be displayed25-(void) Viewwillappear: (BOOL) animated26{27[Super Viewwillappear:yes];NSLog (@"%@-Controller is about to be displayed", [SelfClass]);29}3031//Called when the controller is fully displayed32-(void) Viewdidappear: (BOOL) animated33{34[Super viewdidappear:animated];NSLog (@"%@-Controller Full display", [SelfClass]);36}3738//Call when the controller is about to disappear39-(void) Viewwilldisappear: (BOOL) animated40{41[Super viewwilldisappear:animated];NSLog (@"%@-Controller is about to disappear", [SelfClass]);43}44//Call when the controller disappears completely45-(void) Viewdiddisappear: (BOOL) animated46{47[Super viewdiddisappear:animated];NSLog (@"%@-Controller completely disappears", [SelfClass]);49}5051-(void) Viewwillunload52{53[Super Viewwillunload];NSLog (@"%@-View is about to be destroyed", [SelfClass]);55}5657-(void) Viewdidunload58{59[Super Viewdidunload];NSLog (@ "%@-view is completely destroyed ", [ Self class61 }62 63-(void64 Span style= "color: #000000;" >{65 NSLog (@ "%@ ", [self class66 }67 68  @end           
(1) Run the program, print output as: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. (2) Click the contact button to switch to the second interface. Print output as:Note: First view is removed and the new view is added, but the first view is not destroyed. (3) Click the message screen again to print as follows: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. Uinavigationcontroller and Uitabbarcontroller are managed by a stack, one through an ordinary array.Supplementary Note: The actual height of Uitabbar in Uitabbarcontroller is.Print the Uitabbar frame for viewing in the following method of application.
-(void) applicationdidbecomeactive: (uiapplication *) application{    // 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*) Self.window.rootViewController;    NSLog (@ "%@", Nsstringfromcgrect (Tb.tabBar.frame));}        

Printing results are:

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

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.