Reputation: 354
I've just found out that popoverPresentationControllerDidDismissPopover
method has been deprecated.
What is an alternative method for this?
Upvotes: 12
Views: 2241
Reputation: 10834
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.
Upvotes: 27
Reputation: 2505
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!
Upvotes: 4
Reputation: 1327
Implement UIPopoverPresentationControllerDelegate
and use popoverPresentationControllerDidDismissPopover
method.
Upvotes: -6