如何解雇PushViewController?

问题描述 投票:6回答:7

我的应用程序中有10个viewControllers。我已经使用每个viewController的NEXT按钮上的NavigationController的pushViewController方法推送了所有这些viewControllers。

我已经使用了代码;

[self.navigationController pushViewController:someView animated:YES];

现在我想从第10个子节点(viewController)跳回rootViewController。

我怎样才能做到这一点 ?

请帮我..

谢谢。

ios objective-c iphone ios5
7个回答
16
投票

试着用..

[self.navigationController popToRootViewControllerAnimated:YES];

11
投票

使用此代码:

 [self.navigationController popToRootViewControllerAnimated:YES];

9
投票

试试这个

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:NO];//Use the desired index instead of 1 here

只是回到最后一个屏幕使用这个

[self.navigationController popViewControllerAnimated:YES]

1
投票
 NSInteger index = 0;
 for (UIViewController *view in self.navigationController.viewControllers) {
 if([view.nibName isEqualToString:@"RootViewController"])//put any `XIB name` where u want to navigate 
    break;
index = index + 1;
 }
 [[self navigationController] popToViewController:[[self.navigationController viewControllers] objectAtIndex:index] animated:YES]; 

1
投票

要返回上一个屏幕(视图控制器堆栈的最后一个元素),请弹出视图控制器:

[self.navigationController popViewControllerAnimated:YES];

1
投票

你可以使用[self.navigationController popViewControllerAnimated:YES]特定的视图..


-1
投票

对于SWIFT 4

self.navigationController?.popToRootViewController(animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.