Big Green Alligator
Big Green Alligator

Reputation: 1185

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

Upvotes: 0

Views: 638

Answers (1)

You can use:

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

Upvotes: 1

Related Questions