UITabBarController与UINavigationController异同点浅谈

来源:互联网 发布:战争程序员白濑 动漫 编辑:程序博客网 时间:2024/06/05 08:50

UITabBarController与UINavigationController都可以管理多个视图控制器,并且完成视图控制器的切换,并且UITabBarController中可以嵌套UINavigationController,UINavigationController中也可以嵌套UITabBarController

UITabBarController管理多个视图控制器(被管理的视图控制器是平级关系),通过TabBar上的标签切换显示被管理的controller的页面,而UINavigationController则是有上一个页面推出下一个页面

以微信作为例子,在UITabBarController中可以嵌套UINavigationController

    //创建被tabVC管理的视图控制器    //微信    VchatViewController *vVC = [[VchatViewController alloc] init];    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vVC];    vVC.navigationItem.title = @"微信";    //标签标题    vVC.tabBarItem.title = @"微信";    //设置图片    vVC.tabBarItem.image = [UIImage imageNamed:@"08-chat.png"];    //标签栏标记    vVC.tabBarItem.badgeValue = @"5";        //通讯录    AddressBookViewController *addVC = [[AddressBookViewController alloc] init];    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:addVC];    addVC.navigationItem.title = @"通讯录";    addVC.tabBarItem.title = @"通讯录";    addVC.tabBarItem.image = [UIImage imageNamed:@"24-gift.png"];            //发现    DiscoverViewController *disVC = [[DiscoverViewController alloc] init];    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:disVC];    disVC.navigationItem.title = @"发现";    disVC.tabBarItem.title = @"发现";    disVC.tabBarItem.image = [UIImage imageNamed:@"06-magnifying-glass.png"];    disVC.tabBarItem.badgeValue = @"8";        //我    MeViewController *meVC = [[MeViewController alloc] init];    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVC];    meVC.navigationItem.title = @"我";    meVC.tabBarItem.title = @"我";    meVC.tabBarItem.image = [UIImage imageNamed:@"29-heart.png"];        //设置    SettingViewController *setVC = [[SettingViewController alloc] init];    UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:setVC];    setVC.navigationItem.title = @"设置";    setVC.tabBarItem.title = @"设置";    setVC.tabBarItem.image = [UIImage imageNamed:@"19-gear.png"];    //    //登陆//    LoginViewController *logVC = [[LoginViewController alloc] init];//    logVC.tabBarItem.title = @"登陆";//    logVC.tabBarItem.image = [UIImage imageNamed:@"38-airplane.png"];            //设置TabBar管理的controller    //当controller超过5个的时候,刺痛会自动增加哦一个”more“标签,管理第五个和五个以上的controller,没有出现在底部的controller会以列表的形式通过点击more展示出来    tabVC.viewControllers = @[nav1, nav2, nav3, nav4, nav5];    //设置tabBarController代理    tabVC.delegate = self;
所显示的页面是

当点击某一个标签时,便会切换到标签对应的页面



UINavigationController的推出视图的方法是:这是由当前页面推出ThreeViewController控制的页面

- (void)goToNextVC:(UIButton *)btn{        ThreeViewController *threeVC = [[ThreeViewController alloc] init];        [self.navigationController pushViewController:threeVC animated:YES];}

返回上一个页面

- (void)goBackPreviousVC:(UIButton *)btn1{     [self.navigationController popViewControllerAnimated:YES];}

以上所述只是对两者浅显的对比,我会继续研究的奋斗



0 0
原创粉丝点击