Search code examples
iosxcodesegueviewcontroller

How to add multiple segues from one viewController


I have a UI view controller(viewControllerOne) with a table view in it. I have a segue from a button in the cell to another viewController (viewControllerTwo).

This works fine.
now , i have a third view controller and want to have a segue from another button in View Controller one . How to have multiple segues from one view controller to go to different viewController.


Solution

  • First segue should be between the VC itself ( not a button inside the cell ) to the destinationVC as to be able to send data in prepareforSegue , so from the yellow icon of VC1 drag to both VC2 and VC3 and give a segue identifier like toSecond & toThird respectively then in code do

    // change segue identifier if you want to third 
    self.performSegue(withIdentifier: "toSecond ", sender:nil)