从一个viewcontroller弹出到索引0的tab bar viewcontroller

时间:2015-09-02 10:37:47

标签: swift

如何在swift中从一个viewcontroller弹出到索引0的tab bar viewcontroller。我不知道在哪里使用tabBar.selectedindex = 0以及如何从当前的viewcontroller弹出。如果我正在弹出它转到索引2的tabBarViewcontroller,我实际上是在推送。这是弹出时使用的代码,

let viewControllers: [UIViewController] = self.navigationController!.viewControllers as! [UIViewController]
self.navigationController!.popToViewController(viewControllers[1], animated: true).

1 个答案:

答案 0 :(得分:1)

像这样修改你的代码:

let viewControllers: [UIViewController] = self.navigationController!.viewControllers as! [UIViewController]
self.navigationController!.popToViewController(viewControllers.first(), animated: true)