开发者

UINavigationController: How do I delete a view of a stack

开发者 https://www.devze.com 2022-12-26 04:49 出处:网络
Let say here is my stack layout View3--> Top of the stack View2 View1 HomeView--> Bottom of the stack

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


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


Use popToViewController

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


use...

[self.navigationController popToRootViewControllerAnimated:YES];

0

精彩评论

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