Kurt Anderson
Kurt Anderson

Reputation: 932

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.

Upvotes: 6

Views: 3737

Answers (2)

matt
matt

Reputation: 536047

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

Upvotes: 18

JDM
JDM

Reputation: 893

Try the following in your view

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    return YES;
}

Upvotes: -1

Related Questions