What function is called when a UIViewController is back in focus?

Viewed 1708

I have single view application that also presents a custom popup which I have made using another viewController. The popup viewController has the following assigned:

 presentation: Over current context

enter image description here

when it is presented. When I dismiss this popup viewController to show the first viewController, I would like to know what function gets called so that I can do more stuff within that function. I have tested the following functions below but none of them are called when I have dismissed the popup to reveal the first viewController.

class firstViewController: UIViewController {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        print("viewWillAppear PdfViewController...")   
    }


    override func viewDidLoad() {
        super.viewDidLoad()
    
        print("viewDidLoad PdfViewController ...")
    }
}
1 Answers

This depends on the style overCurrentContext doesn't call viewWillAppear/viewDidAppear , for example fullScreen does , look here for all possible styles

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

if the selected one doesn't call the method then implement delegate for that when you dismiss the modal

//

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)
  }
}
Related