UINavigationController 和 UITabBarController(非基础使用,测试一下思路)

99封情书 提交于 2019-12-06 01:00:28

1、viewController都有nav
2、nav.root=TabBarController 各个viewController 的区别

第一种 每个viewControll对应一个navigationcontroller

      let firstVC=IndexViewController();
      let nav1=UINavigationController(rootViewController:firstVC);
      let image1=UIImage(named:"a");
      nav1.tabBarItem=UITabBarItem(title:"aaa",image:image1,tag:1);
      
      let secondVC=IndexViewController();
      let nav2=UINavigationController(rootViewController:secondVC);
      let image2=UIImage(named:"b");
      nav2.tabBarItem=UITabBarItem(title:"bbb",image:image2,tag:2);
      
      let thirdVC=IndexViewController();
      let nav3=UINavigationController(rootViewController:thirdVC);
      let image3=UIImage(named:"c");
      nav3.tabBarItem=UITabBarItem(title:"ccc",image:image3,tag:3);
      
      let navArr=[nav1,nav2,nav3];
      let tabBarController=UITabBarController();
      tabBarController.viewControllers=navArr;
      root = tabBarController

每个viewcontroller可以修改自己的nav title

第二种 nav的root直接等于tabbarcontroller

      let vc1 = IndexViewController()
      let vc2 = IndexViewController()
      let vc3 = IndexViewController()
      
      let item1:UITabBarItem = UITabBarItem(title: "a", image: nil, tag: 1)
      let item2:UITabBarItem = UITabBarItem(title: "b", image: nil, tag: 1)
      let item3:UITabBarItem = UITabBarItem(title: "c", image: nil, tag: 1)
      
      vc1.tabBarItem = item1
      vc2.tabBarItem = item2
      vc3.tabBarItem = item3
      let tabbar = UITabBarController()
      tabbar.viewControllers = [vc1,vc2,vc3]
      root = UINavigationController(rootViewController:tabbar)

** viewcontroller不能可以修改自己的nav title**

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!