Hope Hope - 1 year ago 110
iOS Question

Swift - How do I segue with a button from ViewController to a specific TabBarController

From a ViewController before a TabBarController in Swift, I would like to send to a specific Tab after the TabBarController that may be a NavigationController or a simple ViewController.

For the moment I make like this:

@IBAction func settingsButtonPressed(sender: AnyObject) {
tabBarController?.selectedIndex = 3 // 4d tab
performSegueWithIdentifier("tabBarShow", sender: self)

With this action, it performs the segue but it always show the first tab.

Thanks for the help!

Answer Source

You can use:

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier == "tabBarShow"){
        if let tabVC = segue.destinationViewController as? UITabBarController{
            tabVC.selectedIndex = 3
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download