一、UITabBarController的初印象
UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就是QQ、微信等应⽤。但是.前者其管理的视图一直存在,而后者在pop后会销毁掉,释放内存.
注意:UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的container viewController中。.
二、UITabBarController的使用:
1、使用步骤:
(1)初始化UITabBarController
(2)设置UIWindow的rootViewController为UITabBarController
(3)创建相应的子控制器(viewcontroller)
(4)把子控制器添加到UITabBarController
2、代码示例
新建一个空的UITabBarController,在控制器中编码
-(void) viewDidLoad {
MapViewController *v1 = [MapViewControllernew];
v1.tabBarItem.image = [UIImageimageNamed:@"icon_map"];
v1.tabBarItem.title = @"地图";
v1.view.backgroundColor = [UIColororangeColor];
CycleViewController *v2 = [CycleViewControllernew];
v2.tabBarItem.image = [UIImageimageNamed:@"icon_cycle"];
v2.tabBarItem.title = @"运动";
v2.view.backgroundColor = [UIColorgreenColor];
OtherViewController *v3 = [OtherViewControllernew];
v3.tabBarItem.image = [UIImageimageNamed:@"icon_other"];
v3.tabBarItem.title = @"活