【问题标题】:Swift Modal ViewController. Is there a easy way to find the result of the ViewControllerSwift 模态视图控制器。有没有一种简单的方法可以找到 ViewController 的结果
【发布时间】:2021-07-30 03:25:59
【问题描述】:

我有一个覆盖模式 ViewController2 的 View(ViewController1)。 ViewController2 有三个选项

  1. 删除所有会话
  2. 选择地点
  3. 取消

在 ViewController1 中启动模态视图控制器是相当容易的

  @objc func presentMenu() {
    let overlayController = ViewController2()
    overlayController.transitioningDelegate = self
    overlayController.modalPresentationStyle = .fullScreen
    present(overlayController, animated: true)
  }

这基本上显示了 ViewController2。但是 viewController1 的代码已经过去了,我在哪里可以发现这个 ViewController2 已经被解除了?

【问题讨论】:

    标签: swift uiviewcontroller


    【解决方案1】:

    您可以实现viewWillAppear 并尝试找出您出现的原因是显示的全屏视图控制器正在被解除。但最好使用呈现的全屏视图控制器告诉它正在被关闭的标准模式。为了让这成为可能,它有一个代表,你要确保它是你:

    overlayController.modalPresentationStyle = .fullScreen
    overlayController.delegate = self
    present(overlayController, animated: true)
    

    然后当覆盖控制器即将被解除时,它会在其委托中调用一个已知方法:

    self.delegate.dismissalIsHappening()
    

    该方法通常通过协议定义,这就是为什么这被称为协议和委托模式。我没有向你展示了整个模式!如果你搜索这个词,你会发现很多完整的例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      相关资源
      最近更新 更多