12/9/2017 - 3:34 PM

Swift - Simple Segue and Unwind Programmatically


Go to ViewController class and add the following method:

@IBAction func fourFiveToggleButton(_ sender: UIButton){
    performSegue(withIdentifier: "mySegueIdentifier", sender: self)

To unwind see: https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/

01. Create an unwind action in the DESTINATION VC where you will unwind to.

@IBAction func unwindToMenu(segue: UIStoryboardSegue) {}

02. Wire up the unwind segue:
Ctrl-Drag from the VC [o] icon on top of the VC in storyboard to the EXIT icon.
Select the @IBAction set up in step 1, from the dropdown menu that appears.

03. Specify a segue identifier:

Expand the Document Outline of the storyboard and select the Unwind segue to 'Exit'
Specify its identifier in the Attributes inspector. Call it the same as the @IBAction func in step 1

04. Trigger unwind segue programmatically.

Create an @IBAction with a button on the SOURCE VC where you will unwind from and add:

self.performSegue(withIdentifier: "unwindToMenu", sender: self)