UINavigationController:如何删除堆栈视图
假设这是我的堆栈布局
View3 --> Top of the stack
View2
View1
HomeView --> Bottom of the stack
所以我现在在 View3
中,如果我单击 Home
按钮,我想加载 HomeView
,这意味着我需要弹出 View3
、View2
和 View1
。但如果我弹出 View3
,View2
将显示。我不想那样。我希望删除 View3
、View2
和 View1
,并显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 popToRootViewControllerAnimated: 到达根视图控制器。这将弹出堆栈中除根视图控制器之外的所有视图控制器。在您的例子中,这将是HomeView。
要访问堆栈中的特定视图,您可以使用 popToViewController:animated: 假设您要弹出第三个视图控制器(从下往上)。在您的情况下,这将是view2:
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.
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:
使用 popToViewController
Use popToViewController
使用...
[self.navigationController popToRootViewControllerAnimated:YES];
use...
[self.navigationController popToRootViewControllerAnimated:YES];