简体   繁体   中英

Swift 2 Return to a selected tab in tab bar controller from view controller

I have a view controller that is loaded up to display some information from a table view cell in a table view which is in a tab bar controller (tab 2). I want to return to tab 1, how can I do this in swift?

I've tried this, but it doesn't seem to work

 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
        }
    }

您可以使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM