ios - PresentingViewController 如何收到其 PresentedViewController 自行关闭的通知?

标签 ios uiviewcontroller coordinator-pattern

给定:

  • 呈现 ViewController B 的 ViewController A
  • ViewController B 没有引用 ViewController A(隐含的 presentingViewController 属性除外)
  • ViewController B 调用 dismiss 并且什么都不做

我想要实现的目标:

  • ViewController A 想知道 ViewController B 何时被解雇以清理某些状态

限制:

  • 我不想使用 KVO
  • 我不想以任何方式修改 ViewController B 或其行为

到目前为止我发现了什么:

  • 解散(动画:完成:) according to the documentation将调用转发给它的 presentingViewController。但似乎 dismiss(animated:completion:) 调用,而是一个私有(private)方法 _performCoordinatedPresentOrDismiss:animated:
  • iOS documentation on presentingViewController具有误导性。它说“呈现的 View Controller 将此属性设置为呈现它的 View Controller ”,但事实并非如此。在 iOS 11 中,这将始终指向 present 被调用的 VC 的根父 VC。同样的 documentation on presentedViewController具有误导性。它说“调用该方法的 View Controller 将此属性设置为它呈现的 View Controller ”,这不是全部。调用 present 的 VC 层次结构中的每个 VC(其所有父 VC 和子 VC)都将指向相同的 presentedViewController

最佳答案

在您的 Controller A 中,将其命名为 UINavigationControllerDelegate 并使用 navigationController:didShowViewController 标记 Controller B 的呈现 (isControllerBisPresented = true)。当 B 的 viewDidAppear 时,检查 isControllerBisPresented 是否为真。

关于ios - PresentingViewController 如何收到其 PresentedViewController 自行关闭的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47350720/

相关文章:

ios - 呈现新的 ViewController 后 Deinit UITabBarController

swift - UIViewController 不取消初始化(mvvm + 协调器)

ios - iOS 物理引擎是否在内部使用 Box2D?我可以直接访问它吗?

iphone - self.interfaceOrientation 导致在 iOS 4.x 上调用 shouldAutorotateToInterfaceOrientation

ios - 分段控制 - 发送到实例的无法识别的选择器

ios - 如果协调器不在 RxSwift 中,那么在 RxSwift + MVVM + 协调器情况下协调器会去哪里?

swift - 无法删除子协调器,因为 transitionCoordinator 在 navigationController 委托(delegate)方法中为 nil

iOS-如何使用动画隐藏/显示 UITabBarController 标签栏?

ios - 在 iOS 和 watchOS 之间共享类

ios - 如何防止 SKAction 序列在解码后重新启动?