UITabBarController, uitabbar

Source: Internet
Author: User

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];

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.