开发者

Popping viewcontroller and then back to RootViewController doesn't seem to work

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开发者_Go百科

[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.


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 :)


There doesn't appear to be any reason to pop back to view controller 3, since you're trying to go to the root before view controller 3's view even appears. Just send -popToRootViewControllerAnimated: to view controller 4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜