UINavigationController:如何删除堆栈视图

发布于 2024-08-28 00:45:12 字数 439 浏览 5 评论 0原文

假设这是我的堆栈布局

View3     --> Top of the stack
View2
View1
HomeView  --> Bottom of the stack

所以我现在在 View3 中,如果我单击 Home 按钮,我想加载 HomeView,这意味着我需要弹出 View3View2View1。但如果我弹出 View3View2 将显示。我不想那样。我希望删除 View3View2View1,并显示 HomeView。知道怎么做吗?

Let say here is my stack layout

View3     --> Top of the stack
View2
View1
HomeView  --> Bottom of the stack

So I am in View3 now, if I click the Home button, I want to load HomeView, meaning that I need to pop View3, View2, and View1. But if I pop View3, View2 will be displayed. I dont want that. I want View3, View2, and View1 be removed, and HomeView will be displayed. Any idea how?

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

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

发布评论

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

评论(3

蓝天白云 2024-09-04 00:45:12

您可以使用 popToRootViewControllerAnimated: 到达根视图控制器。这将弹出堆栈中除根视图控制器之外的所有视图控制器。在您的例子中,这将是HomeView

[self popToRootViewControllerAnimated:YES];

要访问堆栈中的特定视图,您可以使用 popToViewController:animated: 假设您要弹出第三个视图控制器(从下往上)。在您的情况下,这将是view2

NSArray* viewControllersInStack = self.navigationController.viewControllers;
UIViewController* targetViewController = [viewControllersInStack objectAtIndex:2];
[self.navigationController popToViewController:targetViewController animated:YES];

You can use popToRootViewControllerAnimated: to get to the root viewcontroller. This would pop out all the view controllers in the stack except the root view controller. In your case, this would be the HomeView.

[self popToRootViewControllerAnimated:YES];

To get to a specific view in the stack, you can use popToViewController:animated: Assuming you want to pop the third viewcontroller (from bottom up). In your case, this would be view2:

NSArray* viewControllersInStack = self.navigationController.viewControllers;
UIViewController* targetViewController = [viewControllersInStack objectAtIndex:2];
[self.navigationController popToViewController:targetViewController animated:YES];
云裳 2024-09-04 00:45:12

使用 popToViewController

[self.navigationController popToViewController:homeView animated:YES];

Use popToViewController

[self.navigationController popToViewController:homeView animated:YES];
删除→记忆 2024-09-04 00:45:12

使用...

[self.navigationController popToRootViewControllerAnimated:YES];

use...

[self.navigationController popToRootViewControllerAnimated:YES];

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