0

I have the following scenario: I have a view controller and want to navigate programmatically to another view f.e. to give the user the ability to change settings.
So I have VC1 and VC_settings and a present modally segue between those controllers. I gave the segue an identifier and call it like this:

performSegue(withIdentifier: "SegueToSettingsView)

Ok, that works without any problems. The settings view is opened and I can navigate back to VC1.

Now I want to have the same functionality in another view controller VC2. I want to reuse the settings view but the problem is that the segue is already connected between VC1 and VC_settings and I can't connect a new one for VC2.
And if I try to call the existing segue with the coce above in VC2 then the app crashes.

2 Answers 2

0

In swift it is possible to create segues from multiple views two one viewcontroller. Here I have set it so there are segues from VC1 to Settings and VC2 to settings which should work. enter image description here

Hope it helped

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately your screenshot is a bit confusing for me because you only show the dependencies. But can you please describe the steps in Xcode or give a little code snippet how to create/use the segues?
0

Since you have VC1 and VC_settings connected with segue named "SegueToSettingsView" also the perform selector is working fine.

As per your need make another segue from VC2 to VC_Settings and give a different name for it. then make use of below code to perform segue.

performSegue(withIdentifier: "SegueToSettingsViewFromVC2")

Steps to make segue: enter image description here Then select the connection and set identifier

enter image description here

3 Comments

Yes, that was my first idea. But the problem is if I select VC_settings, look under the connections tab and "presenting segues" then I will see that "presenting modally" is already connected. That's clear because it's connected to VC1 but it seems not possible to make a second segue for the same task?
It will come under viewcontroller from where you performing the segue.
definitly you can make anty number of segues as possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.