James
James

Reputation: 1302

Swift create 'universal' segue in tab bar app

I'm a swift newbie and I've got a simple question which I hope someone can help me figure out.

I have a multi-tab app. I created some segues from the tab view controllers on the Stopryboard. I've given the segues identifiers and I'm calling them from my Tab1ViewController code using performSegueWithIdentifier("tab1ToMyTarget", sender: sender) no problem.

However, I'd like to be able to call the segue from any of the app's tabs without creating new segues from the other tabs' view controllers (i.e. I don't want to create "tab2ToMyTarget" - I presume there's a better way!).

My question: Do I create these 'universal' segues on the tab bar view controller (e.g. "tabBarToTarget") (and if so how do I call it from one of my tab view controllers)? ...or...

Do I keep the segue from a single tab view controller (tab1ToTarget) and call that segue from a sibling tab view controller somehow?

Upvotes: 2

Views: 153

Answers (2)

Pranav Wadhwa
Pranav Wadhwa

Reputation: 7746

First, set the view controller that you want to go to's storyboard Id. Then run this:

let vc = storyboard!.instantiateViewControllerWithIdentifier("someViewController")
self.presentViewController(vc, animated: true, completion: nil)

Upvotes: 1

Bhavuk Jain
Bhavuk Jain

Reputation: 2187

You cannot use the same segue to open a controller from a different one. It's better to instantiate a view controller with its storyboard id and then present/show based on the flow.

Upvotes: 1

Related Questions