I have an app that pushes four viewcontrollers on the stack. In the fourth view controller, I do a PopViewController, so I should be back at the 3rd viewcontroller, and in the viewWillAppear method, I do a PopToRootViewController. This does not get me back to the first viewcontroller correctly. The code is straightforward, just a
[self.navigationController pushViewController:nextController animated:YES]
in each of the first 3 viewcontrollers, and in the fourth
[self.navigationController popViewControllerAnimated:YES].
In the 3rd viewcontroller, I have a viewWillAppear method which does:
[self.navigationController popToRootViewControllerAnimated:YES].
As I go through the views, I get the following:
Start app:
Back: Title: FirstLevel
Press OK:
Back: FirstLevel Title: SecondLevel
Press OK:
Back: SecondLevel Title: ThirdLevel
Press OK:
Back: ThirdLevel Title: FourthLevel
Press OK: which pops back 1 and then pops back to root:
Back: FirstLevel Title: ThirdLevel
If I press OK now:
Back: ThirdLevel Title: SecondLevel
I'm sorry if this is confusing. Should I be able to pop back one view controller and then immediately pop back to the root?
Thanks for any help.
Use unwind segue instead of using RootViewController. Using unwind you can go back to any ViewController. DismissViewController always send the controller out from NavigationController.
As suggested by Mark, you should use -popToRootViewController
from your 4rth view controller, instead of 3rd view controller, as your motive is to pop it to root view controller.
BUT if you still want to achieve this functionalty for some anonymous reason, then in the 3rd viewcontroller, use :
[self.navigationController popToRootViewControllerAnimated:YES]
in viewDidAppear
method, instead of viewWillAppear
.
I hope it works :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With