Multi-Controller Management Uitabbarcontroller

Source: Internet
Author: User

Multi-controller management Uitabbarcontroller, similar to Uinavigationcontroller, Uitabbarcontroller can easily manage multiple controllers, easily switch between the controller, such as QQ,.

Header file Definition:

@interface Uitabbarcontroller:uiviewcontroller <uitabbardelegate, nscoding> @property (nonatomic,copy) NSArray *viewcontrollers;//If The number of view controllers is greater than the number displayable by a tab bar, a ' more ' Naviga tion controller would automatically is shown.//the "more" navigation controller would not be returned by-viewcontrollers, But it could be returned by-selectedviewcontroller.-(void) Setviewcontrollers: (Nsarray *) viewcontrollers animated: (BOOL) Animated; @property (nonatomic,assign) Uiviewcontroller *selectedviewcontroller; This could return the "more" navigation controller if it exists. @property (nonatomic) Nsuinteger selectedindex; @property (n onatomic,readonly) Uinavigationcontroller *morenavigationcontroller; Returns the ' more ' navigation controller, creating it if it does not already exist. @property (nonatomic,copy) Nsarray *c Ustomizableviewcontrollers; If Non-nil, then the ' more ' view would include an ' Edit ' button that displays customization UI for The specified controllers. By default, all view controllers is customizable. @property (nonatomic,readonly) Uitabbar *tabbar Ns_available_ios (3_0); Provided for-[uiactionsheet Showfromtabbar:]. Attempting to modify the contents of the tab bar directly would throw an exception. @property (nonatomic,assign) Id<uitabb Arcontrollerdelegate> delegate; @end

Uitabbarcontroller Uitabbar *tabbar Management Uitabbaritem, uitabbar default height 49

IOS6 the height of the previous controller is: screen height-status bar altitude-tabbar height, iOS7 later the height of the controller is the height of the screen

Uitabbar Switching principle: Tab switch to get the view on the controller, the view is added to the screen, the previous view on the screen is removed and will not be destroyed, can be repeatedly switched back and forth, only the controller destroyed or memory warning when the view can disappear.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {NSLog    (@ "%s", __func__);    Override point for customization after application launch.        Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];        Uitabbarcontroller *TABBARVC = [[Uitabbarcontroller alloc] init];    Uiviewcontroller *VC1 = [[Uiviewcontroller alloc] init];    Vc1.view.backgroundColor = [Uicolor Redcolor];    Uitabbaritem *baritem1 = Vc1.tabbaritem;    Baritem1.title = @ "message";            [TABBARVC ADDCHILDVIEWCONTROLLER:VC1];    Uiviewcontroller *VC2 = [[Uiviewcontroller alloc] init];    Vc2.view.backgroundColor = [Uicolor Greencolor];    Uitabbaritem *baritem2 = Vc2.tabbaritem;    Baritem2.title = @ "Friends";            [TABBARVC ADDCHILDVIEWCONTROLLER:VC2];    Uiviewcontroller *VC3 = [[Uiviewcontroller alloc] init];    Vc3.view.backgroundColor = [Uicolor Bluecolor];    Uitabbaritem *baritem3 = Vc3.tabbaritem; Baritem3.title = @ "Dynamic ";            [TABBARVC ADDCHILDVIEWCONTROLLER:VC3];        Self.window.rootViewController = TABBARVC;        [Self.window makekeyandvisible]; return YES;}

Uitabbarcontroller Adding a controller There are 2 ways to add a single sub-controller-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller; Set the sub-controller array @property (nonatomic,copy) Nsarray *viewcontrollers;

If the Uitabbarcontroller has n sub-controllers, there will be N Uitabbarbutton as child controls inside the Uitabbar

What is displayed inside the Uitabbarbutton, determined by the Tabbaritem property of the corresponding sub-controller Uitabbaritem has the following properties affecting the Uitabbarbutton content title text @property (nonatomic,copy ) nsstring *title; icon @property (nonatomic,retain) UIImage *image; icon @property When selected (Nonatomic,retain) UIImage * SelectedImage; reminder number @property (nonatomic,copy) NSString *badgevalue;

Managed controllers access Uitabbarcontroller and Tabbaritem to set tabbaritem corresponding property values through the managed controller

@interface Uiviewcontroller (Uitabbarcontrolleritem) @property (nonatomic,retain) Uitabbaritem *tabbaritem; Automatically created lazily with the view controller ' s title if it's not set explicitly. @property (nonatomic,readonly,r Etain) Uitabbarcontroller *tabbarcontroller; If The View Controller has a tab bar controller as its ancestor, return it. Returns Nil otherwise. @end

Controller view is also a lazy loading mechanism that is used to create a display

View life cycle:

Uitabbarcontroller managed controller, the view in the controller is not destroyed, which is different from the navigation controller (the view displayed before the navigation controller is returned is destroyed)

App Mainstream UI Framework structure

Multi-Controller Management Uitabbarcontroller

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.