UITabBarController, uitabbar
Similar to UINavigationController, UITabBarController can easily manage multiple controllers and switch between controllers. A typical example is QQ and other applications.
UITabBarController
Initialize UITabBarController
Set rootViewController of UIWindow to UITabBarController
Add the corresponding number of subcontrollers using addChildViewController according to the actual situation.
There are two ways to add a controller to UITabBarController:
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 uitabbarbuttons inside the UITabBar as sub-controls.
What is displayed in UITabBarButton is determined by the tabBarItem attribute of the corresponding sub-controller.
UITabBarItem has the following attributes that affect the content of UITabBarButton.
Title text
@ Property (nonatomic, copy) NSString * title;
Icon
@ Property (nonatomic, retain) UIImage * image;
Selected icon
@ Property (nonatomic, retain) UIImage * selectedImage;
Reminder number
@ Property (nonatomic, copy) NSString * badgeValue;
What is the difference between UITabBar and UITabBarController?
One is a control, the other is a view controller, and the View Controller contains a tabbar control! When you jump from view A to view B, If you want B to have tabbar effect, you can let B inherit from tabbarcontroller directly or use viewcontroller and add tabbar in it.
There are some issues with the UITabBarController developed by IOS.
Specify each uitabbaritem in the uitabbarcontroller assembly code, instead of in each included viewcontroller.
UITabbarController * tabController = [[UITabbarController alloc] init];
Self. vc1 = [[UIViewController alloc] init];
Slef. vc1.tabbarItem = ......;
Self. vc2 = [[UIViewController alloc] init];
Self. vc2.tabbarItem = ....;
......
NSArray * vcs = @ [self. vc1, self. vc2,...];
[TabController setViewControllers: vcs];