Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear
function were executed.
Now iOS 13 will present view controllers as a sheet as default, which means the card will partially cover the underlying view controller, which means that viewDidAppear
will not be called, because the parent view controller has never actually disappeared.
Is there a way to detect that the presented view controller sheet was dismissed? Some other function I can override in the parent view controller rather than using some sort of delegate?
Is there a way to detect that the presented view controller sheet was dismissed?
Yes.
Some other function I can override in the parent view controller rather than using some sort of delegate?
No. "Some sort of delegate" is how you do it. Make yourself the presentation controller's delegate and override presentationControllerDidDismiss(_:)
.
The lack of a general runtime-generated event informing you that a presented view controller, whether fullscreen or not, has been dismissed, is indeed troublesome; but it's not a new issue, because there have always been non-fullscreen presented view controllers. It's just that now (in iOS 13) there are more of them! I devote a separate question-and-answer to this topic elsewhere: Unified UIViewController "became frontmost" detection?.
this is not enough. If you have a nabber in your presented VC and a custom bar button that dismisses your view programmatically, presentation controller did dismiss doesn't get called.
Hi @Irina - if you dismiss your view programmatically, you don't need a callback because you dismissed your view programmatically — you know you did it because you did it. The delegate method is only in case the user does it.
@matt Thanks for the answer. When the view is dismissed programmatically this doesn't get called (as Irina says), and you're right that we know we did it. I just think there's an unnecessary amount of boilerplate code to write just to get a kind of 'viewWillAppear' with the new modal presentation style in iOS13. It gets particularly messy when you're managing routing through an architecture where routing is extracted (in MVVM + coordinators, or a router type in VIPER for example)
@AdamWaite I agree but this problem isn't new. We've had this problem for years, with popovers, with non-fullscreen presented view controllers, with alerts, and so forth. I regard this as a serious flaw in Apple's repertory of "events". I'm just saying what the reality is and why. I grapple directly with the issue here: stackoverflow.com/questions/54602662/…
presentationControllerDidDismiss(_:). not called when I click back button in Child VC. Any helps?