Swift 2从视图控制器返回标签栏控制器中的选定选项卡

时间:2016-05-18 07:38:52

标签: ios swift uitableview uitabbarcontroller

我有一个视图控制器,它被加载以显示表视图中的表视图单元格中的一些信息,该视图位于标签栏控制器中(选项卡2)。我想回到标签1,我怎样才能在swift中做到这一点?

我试过这个,但它似乎无法正常工作

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        //TODO: Return to the tab bar
        if segue.identifier == "returnToTab"{
            print("prepare for segue called!")
            tabBarController?.selectedIndex = 2
        }
    }

1 个答案:

答案 0 :(得分:1)

您可以使用:

self.tabBarController?.selectedIndex = 0 //(To return to your first controller)
相关问题