Reputation: 1185
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
Reputation: 644
You can use:
self.tabBarController?.selectedIndex = 0 //(To return to your first controller)
Upvotes: 1