UITabBarController+UINavigationController的混合使用

绝大多数APP都采用UITabBarController+UINavigationController的设计模式,是一种很主流的经典的设计方式。

一、一个 UITabBarController 中嵌套多个 UINavigationController(最流行的方式)

    //1.创建三个子控制器
    ViewController *vc1 = [[ViewController alloc]init];
    
    VCS *vc2 = [[VCS alloc]init];
    
    VCT *vc3 = [[VCT alloc]init];
    
    //2.将三个子控制器去创建导航栏控制器
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    
    //3.初始化UITabBarController
    UITabBarController *TBC = [[UITabBarController alloc]init];
    
    //4.将三个导航栏控制器添加到分栏控制器
    TBC.viewControllers = @[nav1,nav2,nav3];
    
    //5.UITabBarController 的 tabBar 设置不透明
    TBC.tabBar.translucent = NO;
    
    //6.将 UITabBarController 设为根控制器
    self.window.rootViewController = TBC;

二、优点

tabbar 上的标题默认会直接同步到导航控制器上。

每个界面都有自己的导航控制器, 界面跳转都有自己的栈,在后续界面跳转很灵活。

有一些界面可能会透明 UINavigationController ,有一些界面不透明 UINavigationController 且 UINavigationController 有颜色,当这些界面相互跳转时就会出现一些问题。

不管界面怎么跳转,软件结构中 UITabBarController 都只有一个,只需将 UITabBarController 隐藏起来就可以了。

猜你喜欢

转载自blog.csdn.net/qq_36557133/article/details/80903236