Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent UIPopoverPresentationController from being dismissed when clicking outside popover?

In my universal iOS 8 app, I am presenting a popover using using UIPopoverPresentationController as seen below from prepareForSegue:

FavoriteNameViewController *nameVC = segue.destinationViewController;
UIPopoverPresentationController *popPC = nameVC.popoverPresentationController;
popPC.delegate = self;

And with this delegate method.

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}

In this particular case, I'm presenting a view controller that looks like an alert, but isn't.

enter image description here

Now my issue is that the user can click outside of this popover and it gets dismissed. There's no real problem with that except that's not how alerts work and I would like this to emulate an alert.

I see that UIPopoverControllerDelegate had a method called popoverControllerShouldDismissPopover:, but UIPopoverPresentationControllerDelegate doesn't have that method, and I believe I need to use the latter.

like image 966
Kurt Anderson Avatar asked Jul 08 '15 17:07

Kurt Anderson


1 Answers

You need to set the popover controller's passthroughViews to nil and the view controller's modalInPopover to YES.

like image 191
matt Avatar answered Oct 15 '22 23:10

matt