1. The tab bar controller creates and manages the tab bar view and also manages the view controllers that provide the content view for each mode.
2. Each content view controller is designated as the view controller for one of the tabs in the tab bar view.
3.The tab bar controller has its own container view, which encompasses all of the other views, including the tab bar view. The custom content is provided by the view controller of the selected tab.

4.
A standard tab bar interface consists of the following objects:
-
A
UITabBarControllerobject -
One content view controller object for each tab
-
An optional delegate object

5.
You do not modify the tab bar view directly. The tab bar controller object assembles the contents of the tab bar from the UITabBarItem objects provided by your content view controllers.
For each content view controller in your tab bar interface, you must provide a UITabBarItem object with the image and text to be displayed in the corresponding tab.

6.Creating a tab bar controller
- (void)applicationDidFinishLaunching:(UIApplication *)application {
|
tabBarController = [[UITabBarController alloc] init]; |
MyViewController* vc1 = [[MyViewController alloc] init]; |
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init]; |
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil]; |
tabBarController.viewControllers = controllers; |
window.rootViewController = tabBarController; |
} |
7. Creating the view controller’s tab bar item
UIImage* anImage = [UIImage imageNamed:@"MyViewControllerImage.png"]; |
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:anImage tag:0]; |
8. You can associate tab bar items with your view controllers at any time before displaying your tab bar interface. You do this by assigning the tab bar item to the tabBarItem property of the corresponding view controller.
浙公网安备 33010602011771号