I've just found out that popoverPresentationControllerDidDismissPopover
method has been deprecated.
What is an alternative method for this?

- 713
- 2
- 7
- 26

- 324
- 2
- 12
3 Answers
It appears that the UIPopoverPresentationControllerDelegate
protocol includes the UIAdaptivePresentationControllerDelegate
protocol, which has
// Called on the delegate when the user has taken action to dismiss the presentation successfully, after all animations are finished.
// This is not called if the presentation is dismissed programatically.
@available(iOS 13.0, *)
optional func presentationControllerDidDismiss(_ presentationController: UIPresentationController)
and presentationControllerDidDismiss()
appears to be called when the popover is dismissed.

- 10,668
- 5
- 59
- 68
-
This should be correct answer. As if you go to the definition of `UIPopoverPresentationControllerDelegate`. ``` // Called on the delegate when the user has taken action to dismiss the popover. This is not called when the popover is dimissed programatically. - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController API_DEPRECATED_WITH_REPLACEMENT("presentationControllerDidDismiss:", ios(8.0, 13.0)); ``` – wzhang84 Mar 30 '20 at 16:02
Sadly, Apple's documentation leaves no hint. I would solve things this way.
You setup the popover and obtain the UIPopoverPresentationController
like so:
UIViewController* controller = [[MyCustomViewController alloc] init];
controller.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:controller animated:YES completion:nil];
UIPopoverPresentationController* pc = [controller popoverPresentationController];
pc.sourceView = self.view;
pc.sourceRect = CGRectZero;
The controller
object here represents the main view controller wrapped by the popover—your custom view controller. I think your best bet is to override the -viewDidDisappear:
method of your custom view controller. That method will be called when the popover presentation controller dismisses the popover.
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSLog(@"%@ - %@", NSStringFromSelector(_cmd), self);
// Do the needful.
}
I think it is a shame on Apple that they provided no rationale for the deprecation or suggestions as to how to handle it. Hope that helps!

- 2,397
- 2
- 24
- 41
-
3This answer not fully correct, the proper one is https://stackoverflow.com/a/60234956/721929. And API headers inside UIKit UIPopoverPresentationController.h advice a replacement with presentationControllerDidDismiss and presentationControllerShouldDismiss – kikeenrique Oct 15 '20 at 16:37
-
Thank you. What you link to would be the preferred solution. It would have been nice if Apple could have just put that in their documentation, instead of the header file only. – Mario Oct 16 '20 at 19:15
Implement UIPopoverPresentationControllerDelegate
and use popoverPresentationControllerDidDismissPopover
method.

- 1,317
- 1
- 17
- 32