我有一个带有2个标签的tabBarController:
tab0,tab1
在tab0中我有一个包含3个子视图的navigationController
viewA(root),viewB,viewC
在viewC中按一个按钮将使用代码
将我带到tab1@IBAction func switchButtonTapped(sender: UIButton){
tabBarController.selectedIndex = 1
}
我遇到的问题是,一旦切换到tab1,我就无法将tab0重置为viewA(它的根vc),它会保留在viewC上。
如何从tab0切换到tab1,同时重置tab0中的视图?
由于我同时切换标签并重置导航控制器的vcs应该在不同的线程上发生吗?
@IBAction func switchButtonTapped(sender: UIButton){
tabBarController.selectedIndex = 1
dispatch_async(dispatch_get_main_queue(), {
self.navigationController?.popToRootViewController(animated:true)
}
}
答案 0 :(得分:2)
注意:Swift 3代码:
@IBAction func switchButtonTapped(sender: UIButton){
tabBarController?.selectedIndex = 1
navigationController?.popToRootViewController(animated: true)
}
这对我来说很好(它选择了第二个标签,当我点击第一个标签按钮时,它会显示第一个标签的root -first-ViewController)。