0

I have three ViewControllers. I want to perform a segue from the ThirdViewController to the SecondViewController when you click on the Ok Button of an alert showing up. I already tried with this code:

alert.addAction(UIAlertAction(title: "Ok!", style: UIAlertActionStyle.default, handler: { action -> Void in
     self.performSegue(withIdentifier: "ThirdViewControllerSegueBack", sender: self)
}))

The problem is that a new window of the SecondViewController shows up, so when I click back on the navigation bar it leads me back to the ThirdViewController. I want it to show the FirstViewController.

Vega
  • 23,736
  • 20
  • 78
  • 88
  • 2
    You need an unwind segue: https://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them – Shades Sep 30 '17 at 11:31
  • Try this if it works in your scenario: https://stackoverflow.com/questions/45792130/unwind-then-segue-without-showing-intermediate-view-controller/45792543#45792543 – Amit Sep 30 '17 at 11:34
  • just have a look at this how-to: (unwind segues) https://medium.com/@mimicatcodes/create-unwind-segues-in-swift-3-8793f7d23c6f – AlexWoe89 Sep 30 '17 at 13:54

1 Answers1

0

In SecondViewController you must create the Unwind segue

@IBAction func unwindToController2(segue:UIStoryboardSegue) { } 

The on storyboard in ViewController3 drag from ViewController to exit Button and add segue. Add identifier to it, and call in UIAlertControllerenter image description here

maxkoriakin
  • 287
  • 2
  • 6