我有六个tabItem视图控制器,每个子视图控制器本身都有一个导航控制器。更改selectedIndex之后,我有一个问题来推送新的视图控制器。我使用AZTabBarController创建了一个tabbar变量。
//the viewcontroller I want to push
let vc = self.storyboard?.instantiateViewController(withIdentifier: "CreateArticleViewController") as! CreateArticleViewController
//this can changing my tabbar selected index well.
self.currentTabBar?.setIndex(3, animated: true)
// Below code doesn't work
self.navigationController?.pushViewController(vc, animated: true)
self.currentnavigationController?.pushViewController(vc, animated: true)
tabcontroller->导航1-> A1-> A2
->导航2-> B1-> B2-> B3-> B4
->导航3-> C1-> C2-> C3-> C4
->导航4-> D1-> D2-> D3-> D4
->导航5-> E1-> E2-> E3
->导航6-> F1-> F2-> F3
例如,当我点击A1中的按钮时,如何更改索引并将视图控制器推到D3? 我应该使用自定义委托来完成此技巧吗? 请查看我的故事板的快照。 https://imgur.com/a/X860m7p
答案 0 :(得分:0)
更改selectedIndex
时,您按的导航键是A而不是新的D,因此您需要
self.currentTabBar!.setIndex(3, animated: true)
let dNav = self.currentTabBar!.viewControllers[3] as! UINavigationController
dNav.pushViewController(vc, animated: true)