重要思想:: TabBar 管理 Navigation, 然后 Navigation管理自己的界面(界面跳轉)
注意::::: Navigation 中的 ViewControllers 數(shù)組是一個棧,一旦 pop 以后就沒了,
但是 TabBar 中的 ViewControllers 數(shù)組不會消失.只是一個單純的數(shù)組.
UITabBarControl:
//顯示第一個界面, 加入導航控制器
MainViewController *mvc = [[MainViewController alloc] init];
//設置title顯示導航條上
mvc.title = @"主界面";
mvc.tabBarItem.image = [UIImage imageNamed:@"tab_0.png”];
mvc.tabBarItem.badgeValue = @"999";
//創(chuàng)建導航控制器, 讓導航控制器管理mvc
// 設置一個普通視圖控制器作為根視圖控制器
UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:mvc];
//創(chuàng)建第二個界面
ContactsViewController *cvc = [[ContactsViewController alloc] init];
cvc.title = @"聯(lián)系人";
cvc.tabBarItem.image = [UIImage imageNamed:@"tab_1.png"];
UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:cvc];
//第三個界面
DynamicViewController *dvc = [[DynamicViewController alloc] init];
dvc.title = @"動態(tài)";
dvc.tabBarItem.image = [UIImage imageNamed:@"tab_2.png"];
UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:dvc];
//第四個界面
SettingViewController *svc = [[SettingViewController alloc] init];
svc.title = @"設置";
svc.tabBarItem.image = [UIImage imageNamed:@"tab_3.png"];
UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:svc];
//創(chuàng)建標簽欄
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = @[nc1,nc2,nc3,nc4];
self.window.rootViewController = tbc;
//標簽欄默認高度49
[tbc.tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
//設置選中的顏色
tbc.tabBar.tintColor = [UIColor redColor];