-
First wire a segue for each viewController. control-drag from the viewController icon at the top of
ViewControllerA
to anotherViewController
and select the segue type. -
Click on the segue arrow between the viewControllers, and set its identifier in the Attributes Inspector on the right.
- Repeat steps 1 and 2 for each
ViewControllerB
,ViewControllerC
andViewControllerD
giving their segues unique id’s such as"segueToB"
,"segueToC"
and"segueToD"
. -
In your button code, do the following:
let idx = mySegment.selectedSegmentIndex let segueID = ["segueToB", "segueToC", "segueToD"][idx] self.performSegue(withIdentifier: segueID, sender: self)
Demo of connecting two segues:
6
solved Different ViewController if different selectedSegmentIndex