Domanda

I have a user registration process which is separated out into 3 screens. The first screen has user to enter his mobile number, the second screen asks him select his location & the third screen asks him to enter his birthday and a few other details.

So in total, there are totally 3 controllers which I have used and are presented in the below order.

1) mobile_number_controller.rb 2) location_controller.rb 3)miscellaneous_details_controller.rb

So I present this as a chain of controllers all using modal segues as a result of the discussion here. Right now I am kind of confused on unwinding back. The questions that I have in mind are

1) Is it possible to unwind back to a controller up in the chain of presenting controllers but not the controller which directly presented the current controller, i.e from miscellaneous_details_controller to mobile_number_controller? If possible is it a right way to do so?

2) If 1) is possible, then what would happen to other controllers in the chain, i.e all the controllers between the current controller and the presenting controller up in the chain to which we are unwinding back now, i.e, location_controller? Will I have to manually dismiss all controllers one by one and where do I do that?

Please suggest on the rightful ways to approach this problem. Any help would be of great use as I am just starting of with my iOS development.

È stato utile?

Soluzione

The easiest way is not to use an unwind segue at all. Just call dismissViewControllerAnimated:completion:, sending it to the view controller instance you want to wind back to. This will cause all presented view controllers to be removed all the way back to the one you sent it to.

You can figure out which view controller this is because there is a chain of presentingViewController objects running all the way back to it. In other words, to go back one step, you say:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

To go back two steps, you say:

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

Altri suggerimenti

I solved this using child view controllers. For the first view controller you show, present it in the normal way:

self.presentViewController(myViewController, animated: true, completion: nil)

Once inside that view controller, add a subsequent view controller as a child view controller. You have to manually animate it, but that's a breeze:

addChildViewController(childViewController)
view.addSubview(childViewController.view)
childViewController.view.frame = view.bounds

let startTransform = CGAffineTransformMakeTranslation(0, CGRectGetMaxY(view.bounds))
childViewController.view.transform = startTransform

UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .BeginFromCurrentState, animations: {
        childViewController.view.transform = CGAffineTransformIdentity
        }, completion: { (_) in
            //I wanted to change my status bar color here, do whatever you need
            UIApplication.sharedApplication().setStatusBarStyle(.Default, animated: true)
    })

Now, if you want to dismiss the entire thing, you just call:

self.dismissViewControllerAnimated(true, completion: nil)

And if you want to dismiss only the childViewController you re-animate the view controller back down and then remove it:

childViewController.view.transform = CGAffineTransformIdentity

UIView.animateWithDuration(0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .BeginFromCurrentState, animations: {
    let endTransform = CGAffineTransformMakeTranslation(0, CGRectGetMaxY(self.view.bounds))
    childViewController.view.transform = endTransform
    }, completion: { (_) in
        //remove child view controller
        childViewController.removeFromParentViewController()
        childViewController.view.removeFromSuperview()
})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top