I have 4 ViewControllers in my storyboard. I want all of them to be able to access my "Settings" ViewController by performSegue. Is it possible to have ONE segue to perform this, instead of ctrl + drag from each and every ViewController to my "Settings" ViewController?
-
If you want to use a segue then there needs to be a segue from each source to the destination. Alternatively you can just instantiate the settings view controller and push/present it without using a segue – Paulw11 May 18 '16 at 05:43
-
I was afraid of this answer. The fact that I have to drag segues from all four controllers to the same one is way way ugly, but if I have to I will – George Asda May 18 '16 at 05:48
4 Answers
No its not possible with a single segue. You need 4 different segues from 4 different ViewControllers
. But you can do this programatically.
Make an extension for UIVIewController
extension UIViewController
{
func showSettingsScreen()
{
let storyBoard = UIStoryboard(name: "YourStoryBoardName", bundle:nil)
let settingsScreen = storyBoard.instantiateViewControllerWithIdentifier("YourSettingsViewControllerID")
self.navigationController?.pushViewController(settingsScreen, animated: true)
}
}
Now you can call showSettingsScreen()
from any of your view controllers(Make sure this view controller has a navigation controller).

- 2,441
- 1
- 11
- 30
I really dont think so there is a way to do so. U ought to connect ur SettingsViewController to all of your 4 View Controllers, add segue , and define a segue identifier which is used in
prepareForSegue:sender:
or
shouldPerformSegueWithIdentifier:sender:
methods. U can access segues through these identifiers. If u find "ctrl + drag from each and every ViewController to "Settings" ViewController " tasky you can opt for Navigation Controller as well. U just have to embed Navigation Controller in your storyboard and define Storyboard Id for every View Controller and you are done. Just use storyboard id of view controller to be instantiated and u good to go.
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self.navigationController pushViewController:vc animated:YES];
Apart for assigning storyboard id you dont have to worry about storyboard ,No ctrl+drag thing.
I thought of one more elegant solution i.e. using Container View. You can take button to switch, SettingsViewController as common, in your Container View Controller while displaying every ViewController. happy Coding..

- 2,731
- 1
- 12
- 19
You cannot do that. A segue has only one source and one destination. You could programatically instantiate your Settings ViewController
and display it either by using push or by using present. What you should think of though is why do you have to go to settings from so many places. It might be a sign of bad design and duplicate code. Usually applications have only one such button/action that can be accessed from multiple screens (by using some kind of container view implementation) or from only one screen.

- 4,522
- 6
- 26
- 42
There is one way to do this. Create a root view controller and matching view which contains a single embedded view. Add your segue to this root controller. Then in your app you switch in the other view controllers using standard child container techniques. This is pretty much the concept that UINavigationControllers use.
One advantage from this is that if you want to have common elements which are visible to all controllers then you can add them to your root controller.
But it all depends on what you are trying to achieve.

- 20,957
- 14
- 79
- 135