问题描述
我想知道是否可以使用导航控制器按钮返回前2页.现在,我已经使用此代码自定义了按钮
I'm wondering whether it's possible to go back to 2 previous page using navigation controller button. Right now, I've custom made the button using this code
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:mainLib.navCountryTitle
style:UIBarButtonItemStyleBordered
target:self
action:@selector(handleBack:)];
在'handleback'方法上,我叫这行
And on 'handleback' method, I called this line
[self.navigationController popViewControllerAnimated:YES];
因此,在这种情况下,它将转到上一个屏幕.但是我想转到上一个屏幕之前的屏幕.
So in this case it will go to the previous screen. However I want to go to the screen before the previous screen.
我知道我可以立即调用该屏幕,但是我不想这样做,因为在每个屏幕中都有一个后退按钮,该按钮应该转到上一个屏幕.
I know that i can call that screen straight away, but I wouldn't want to do that because in every screen I have a back button which supposed to go to its previous screen.
推荐答案
您可以使用其推入索引弹出到特定的viewcontroller.如果您知道语法,则可以像
You can pop to particular viewcontroller using its pushing index. If you know the syntax than you can do that like
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:indexOfViewController] animated:YES];
我相信,您的情况将是第一指数.虽然您可以再次更改索引并检查.
I believe, In your case it would be 1st Index. Though you can again change index and check.
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
此处self.navigationController.viewControllers是所有已推送的ViewController的数组.
Here self.navigationController.viewControllers is the array of the all the ViewControllers pushed.
希望有帮助.
这篇关于导航控制器的“后退"按钮转到上一个屏幕之前的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!