Why does my unwind segue go back too far?
Asked Answered
V

1

3

I'm trying to create the controller architecture for the signup process of my app. Below is an image of the current state:

Controller Architecture

The app starts at a login page the first time and if the user clicks "SignUp", a navigation controller is presented modally via self.presentViewController. The navigation controller then pushes through a view controller which then pushes to a second view controller. On this second view controller the user must first press "Go" to modally navigate to a view controller that requests additional information before continuing the signup process. Once the user inputs additional information on this modally presented controller, the user presses "Go Back" to return to the second view controller via an unwind segue.

However, when this is pressed the unwind segue returns to the second view controller but then immediately returns to the "Log In" page. It seems like the unwind segue pops off all modally presented views even though the unwind function is nested within the second view controller.

What's going on and what is the solution to unwinding to the second signup page?

Visually answered 17/10, 2015 at 0:56 Comment(2)
Just checking before I try to reproduce this: so the unwind function appears only in the SecondPage view controller code? — And is this iOS 9? The behavior of unwind segues is greatly changed in iOS 9 so it is important to know.Eyespot
Yeah, it only appears in the SecondPage view and this is iOS 9.Visually
S
8

I had this same issue and it was usually caused by one of the following reasons:

  1. Using a deprecated segue
  2. Calling viewController.dismissViewControllerAnimated inside the @IBAction method used for unwind.
  3. Having the @IBAction used for unwind in the wrong controller. The @IBAction should in the controller you want to unwind to.

Steps to unwind a segue

  1. Create an @IBAction method in SecondSignupController this method will be called upon unwind. This method should take a UIStoryboardSegue as an argument example -> @IBAction func onUnwindFromModalPage(segue:UIStoryboardSegue){}. The main purpose of this method is to pass back data if any otherwise you can leave it empty.

  2. Control-Drag from Go-Back button to exit symbol in the Modally Presented Controller in storyboard. The exit symbol is the last symbol on top of the controller when a controller is selected. This will show you a list of @IBActions that you can choose for unwind. Choose the method you created in the SecondSignUpController.

Seamark answered 17/10, 2015 at 1:29 Comment(5)
Yes, the fact that the OP sees this in two stages makes me wonder whether he has other code that causes the extra unwinding.Eyespot
@Seamark Unfortunately, I followed those exact steps in creating the segue. And I'm certain that none of the possible reasons you presented are applicable to my situation.Visually
When I delete the @IBAction used for unwind in the second view controller, pressing the Go Back button doesn't do anything. It simply stays on the modally presented controller.Visually
So I copied the exact same situation in a new storyboard and it worked just fine. Exact same code and segues. One thing to note though, the very first time I ran this I did have self.dismissViewControllerAnimated(true, completion: nil) within the @IBAction for the unwind segue. I deleted this but somehow the behavior stuck even after cleaning and rebuilding?Visually
If you removed the IBAction from second controller and no previous controllers has your unwind IBAction nothing will happen. Unwind segue looks for the first previous controller that implements the method. I think your problem was dismissViewControllerAnimated it dismissed the modally presented controller first and then the entire navigation controller bringing you back to login controller. Its odd that it worked first time with it.Seamark

© 2022 - 2024 — McMap. All rights reserved.