Disable and pop view controller
I want to go back two levels in the view controller stack. I have three segments in this order: Show, Show, Present Modally. Navigation controller is used. From my 4th view, I want to go back to the second view. I tried to use self.presentingViewController?.presentingViewController?.navigationController?.popViewControllerAnimated(false);
and
self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(false, completion: nil);
The second only works if the 2nd and 3rd segments are like 'Present Modally'. How can I make them work with layoffs and pop music?
source to share
Try dismissing the presented view controller before inserting the other two:
func dismissThenDoublePop() {
// Get the presenting/previous view
let previousView = self.presentingViewController as UINavigationController
// Dismiss the current view controller then pop the others
// upon completion
self.dismissViewControllerAnimated(true, completion: {
// Get an array of the current view controllers on your nav stack
let viewControllers: [UIViewController] = previousView.viewControllers as [UIViewController];
// Then either pop two view controllers, i.e. pop
// to viewControllers[viewControllers.count - 2], or
// pop to the second view controller in the nav stack,
// i.e. viewControllers[1]. (In this case I've used the
// first option.)
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);
});
}
source to share
You can use this method
fooobar.com/questions/14221 / ...
Simple and clean (unwind segments)
@IBAction func unwindAction(segue: UIStoryboardSegue) {
}
source to share
Just call the dismiss function ofViewControllerAnimated.It will automatically disable all view controllers, including the presented model view controller.
Target - C
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
Swift
self.navigationController?.dismissViewControllerAnimated(false, completion: nil);
source to share