导航控制器后退按钮可转到上一屏幕之前的屏幕

发布于 2024-11-02 16:39:48 字数 574 浏览 4 评论 0原文

我想知道是否可以使用导航控制器按钮返回到上一页。现在,我已经使用此代码自定义了按钮

self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:mainLib.navCountryTitle
                                 style:UIBarButtonItemStyleBordered
                                target:self
                                action:@selector(handleBack:)];

,在“handleback”方法中,我调用了这一行

[self.navigationController popViewControllerAnimated:YES];

所以在这种情况下它将转到上一个屏幕。但是我想转到上一个屏幕之前的屏幕。

我知道我可以立即调用该屏幕,但我不想这样做,因为在每个屏幕中我都有一个后退按钮,该按钮应该转到其上一个屏幕。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北凤男飞 2024-11-09 16:39:48

您可以使用其推送索引弹出到特定的视图控制器。如果您知道语法,那么您可以像

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:indexOfViewController] animated:YES];

我相信的那样这样做,在您的情况下,它将是第一个索引。尽管您可以再次更改索引并检查。

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

这里 self.navigationController.viewControllers 是推送的所有 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];

Here self.navigationController.viewControllers is the array of the all the ViewControllers pushed.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文