UINavigationController 和 UITabBarController(非基礎使用,測試一下思路)

一、viewController都有nav
二、nav.root=TabBarController 各個viewController 的區別code

第一種 每一個viewControll對應一個navigationcontrollerit

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 titleio

第二種 nav的root直接等於tabbarcontrollerim

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**tab

相關文章
相關標籤/搜索