ios - 解除 View Controller 动画 :Completion: Concept?

标签 ios uiviewcontroller modalviewcontroller

我有 3 个 View Controller - BaseViewController->AviewController->BviewController。

AviewController 以模态方式呈现在 BaseViewController 上,BviewController 以模态方式呈现在 AviewController 上。

在 AviewController 中,如果我调用 [self dismissViewControllerAnimated:Completion]它同时关闭 AviewController 和 BviewController。

在 BviewController 中,如果我调用 [self.presentingViewController dismissViewControllerAnimated:completion]它只会关闭 BviewController。
为什么 AviewController 没有被解雇?

难道这个概念错了AviewController = BviewController.presentingViewController。 ?

我还尝试在 BviewContrroller 中对 AviewController 进行弱引用并试图解除。但仍然只有 BviewController 单独被解雇。
[AviewControllerReference dismissViewControllerAnimated:completion]
我对这个概念的理解有什么错误吗?

最佳答案

来自苹果文档:

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.



因此,您必须在呈现 VC 时调用此方法来关闭呈现的 Controller 。没有自己提出 Controller 。正如您在上面的粗体测试中看到的那样,如果您在呈现的 VC 上调用它,它会自动将该方法转发给正在呈现的 VC。

所以要回答你的问题,

在 BViewController 上调用下面的行来解除这两个 AViewcontrollerBViewController . ,
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 

这相当于调用 dismissViewController:在您的 BaseViewController 上.解雇AViewController的正确方法是什么?

关于ios - 解除 View Controller 动画 :Completion: Concept?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22988091/

相关文章:

html - 使用 Materialise 卡与模态视图冲突

ios - 模态视图 Controller UI 在 presentViewController :animated:completion: 后没有响应

ios - 呈现模态时滑动到 UIPageViewController 中的不同 View Controller

ios - 如何在一个 View Controller 中定义 Action 并在任何地方调用它们

ios - 制作新格式(例如 ".rcb")

ios - 是否可以更改 UITabBarController 中的 View Controller 框架,以便 UITabBarController View 可见?

iOS:AutoresizingMask 未调整大小以适应屏幕上的 map 或 View

ios - 临时打开新ViewController时保存值

ios - 快速转换问题

ios - 如何处理来自 iOS 设置的推送通知允许