UIPresentationController delegate how to set

3.7k Views Asked by At

In iOS 13, viewWillAppear is not called when dismissing view controller. As a workaround, it is mentioned to override UIAdaptivePresentationControllerDelegate delegate, but it's not working for me. What am I doing wrong?

 func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "MyVC" {
       let destination = segue.destination as! MyViewController
        destination.presentationController?.delegate = self
    } 
  }

And then,

func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
     resumePipeline() //<--Does not get called
}
1

There are 1 best solutions below

3
matt On

What am I doing wrong?

You're probably assuming that presentationControllerDidDismiss is always called when the dismissal takes place. That's a false assumption. It is called when the user drags down on the presented view to dismiss it.

You need to think of the presented view controller as if it were a popover. It isn't completely replacing the presenting view controller's view; it just covers it partially. So there is no viewDidAppear call, because the main view never disappeared.

Either you need to go back to forcing your presented view controller to be fullScreen or you need to adapt your architecture to work with the new style of presented view controller.