Why does my unwind segue go back too far?

2020-04-11 19:03发布

问题:

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

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?

回答1:

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.