UITabBarController (Label bar Controller), uitabbarcontroller

Source: Internet
Author: User

UITabBarController (Label bar Controller), uitabbarcontroller

I. Basic concepts of the label bar Controller

The UITabBarController inherits from the View Controller and manages the View Controller in the form of tag bar items. The view controllers of each tag bar are independent of each other and do not affect each other.

(1) the life cycle of each View Controller in UITabBarController is consistent with that of UITabBarController;

(2) Click the items (UITabBarItem) in different tabs to display the views of different View controllers;

(3) The View of the View Controller corresponding to the selected tab bar is displayed, and the View of other View controllers is unmounted.

Ii. Advantages of the label bar Controller

(1) modular applications, low coupling between modules, and easy division of labor for team development;

(2) Applications are highly scalable and can selectively add or delete modules as needed.

3. Create a label bar

Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; RootViewController * rootCtrl = [[RootViewController alloc] init]; // create a navigation controller UINavigationController * navCtrl = [[UINavigationController alloc] initWithRootViewController: rootCtrl]; navCtrl. title = @ "Homepage"; // create a view UIViewController * vc1 = [[UIViewController alloc] init]; vc1.title = @ "favorites "; UIViewController * vc2 = [[UIViewController alloc] init]; vc2.title = @ "Search"; UIViewController * vc3 = [[UIViewController alloc] init]; vc3.title = @ "set "; NSArray * controllers = [NSArray arrayWithObjects: navCtrl, vc1, vc2, vc3, nil]; // create the instance UITabBarController * tabCtrl = [[UITabBarController alloc] init] for the Controller on the tab bar. // assign the array containing the View Controller instance to tabCtrl. viewControllers = controllers; // The default value is 2nd view tabs (index starts from 0) tabCtrl. selectedIndex = 1; // Add the view of tabBarController as a subview to window self. window. rootViewController = tabCtrl;

 

Related Article

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.