UIViewcontroller重新成为焦点时会调用什么函数?

时间:2018-08-28 13:22:18

标签: ios swift uiviewcontroller

我有一个单视图应用程序,该应用程序还呈现了一个使用另一个viewController创建的自定义弹出窗口。弹出的viewController分配了以下内容:

 presentation: Over current context

enter image description here

显示时。当我关闭该弹出的viewController以显示第一个viewController时,我想知道调用了哪个函数,以便可以在该函数中做更多的事情。我已经在下面测试了以下函数,但是当我关闭弹出窗口以显示第一个viewController时,没有一个被调用。

class firstViewController: UIViewController{

 override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)

     print("viewWillAppear PdfViewController...")

   }


override func viewDidLoad() {
    super.viewDidLoad()

    print("viewDidLoad PdfViewController ...")


   }

}

1 个答案:

答案 0 :(得分:3)

这取决于样式overCurrentContext不会调用viewWillAppear / viewDidAppear,例如fullScreen会在这里查找所有可能的样式

https://developer.apple.com/documentation/uikit/uimodalpresentationstyle

如果所选对象未调用该方法,则在关闭模式时实现该委托

//

protocol DimissManager {
  func vcDismissed()
}
class FirstVc:UIViewController,DimissManager {

 func vcDismissed() {
   print("Dismissed")
 }
 func showSecond() {
    let sec = storyboard
    sec.delegate = self ...... // note this assign may be in prepareForSegue if you use segues  
    self.present(sec.......
 }
}
class SecondVc:UIViewController{
   var delegate:DimissManager?

  @IBAction func dismiss(_ sender:UIButton) {
    delegate?.vcDismissed()
    self.dismiss(animated:true,completion:nil)
  }
}