ios - 弹出 View Controller ,然后同时关闭前一个 View Controller

标签 ios objective-c uiviewcontroller uinavigationcontroller

我的主视图 Controller A 呈现 View Controller B,然后将 View Controller 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/

相关文章:

c++ - 在 iOS 中启用异常

ios - 单击一个 View Controller 中的按钮将在另一个 View Controller 中推进进度条

iOS:将 subview 添加到第二高位置

ios - 多个 UIViewController 的单个背景图像

ios - 具有比例宽度和文本驱动高度的动态 UILabel

c++ - 在 iPhone 应用程序中从 C++ 调用 Objective-C 函数

ios - 在没有 ssl 证书的情况下在 WebView 中打开 Https URL

ios - 使用 Objective C 创建 JSON 数据并将其发送到服务器

Objective-C - 如何使用 NSInteger 初始化枚举?

swift - 快速在屏幕上移动一个像素