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;