我的主视图控制器A提供了视图控制器B,然后将视图控制器C推入其(B的)导航堆栈中。现在,从C开始,我希望可以直接转到A。如果我从C运行dismissViewController,则动画不流畅,并且如果我将C弹出到B然后关闭B,则有两个单独的/截然不同的动画,它们分别是我不想。
我有没有办法在不进行中间过渡的情况下直接从C转到A?
因此,运行以下命令(来自C)显示了突然的过渡
[self dismissViewControllerAnimated:YES completion:nil];
而运行以下内容(来自C)显示了两个单独的转换...
UIViewController *previousViewController = [self.navigationController.viewControllers
objectAtIndex:(self.navigationController.viewControllers.count - 2)];
[self.navigationController popViewControllerAnimated:YES];
[previousViewController dismissViewControllerAnimated:YES completion:nil];
最佳答案
使用popToViewController:animated:
[self.navigationController popToViewController: self.navigationController.viewControllers.firstObject animated: YES];
或者,使用
setViewControllers:animated:
NSMutableArray* viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeLastObject];
[viewControllers removeLastObject];
[self.navigationController setViewControllers: viewControllers animated: YES];
关于ios - 弹出 View Controller ,然后同时关闭以前的 View Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40916931/