Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way NOT to have the popover dismissed when pressing outside it?

I know the SDK documentation says

Taps outside of the popover’s contents automatically dismiss the popover.

But I'm sure the smart people here found a way :) maybe I should overwrite the popover dismiss function?

Thanks

EDIT: I tried using the passthroughViews as was suggested here, and it works perfectly. Here's the code for whoever needs it - in this example, I put self.view in the array, which means that where ever outside the button where the popover was originated, nothing dismiss the popover.

        popoverController.passthroughViews = [[[NSArray alloc] initWithObjects:self.view, nil] autorelease];
like image 691
Lior Frenkel Avatar asked Mar 29 '11 18:03

Lior Frenkel


2 Answers

You need to set the passthroughViews property. From the documentation:

An array of views that the user can interact with while the popover is visible.

@property (nonatomic, copy) NSArray *passthroughViews

When a popover is active, interactions with other views are normally disabled until the popover is dismissed. Assigning an array of views to this property allows taps outside of the popover to be handled by the corresponding views.

Set passthroughViews to an array of view(s) that you want to handle the touch event instead of just dismissing the popover.

like image 69
indragie Avatar answered Oct 17 '22 00:10

indragie


There is a very simple and legit solution. In the view controller that presents your UIPopoverController, conform to the UIPopoverControllerDelegate protocol and implement the following delegate method. I just tested this and it does prevent popover to dismiss.

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    return NO;
}

Just make sure that you have set the delegate of your popover controller to the view controller that implements this.

You can dismiss the popover by using [popoverController dismissPopoverAnimated:NO]; method.

like image 27
Sam Avatar answered Oct 17 '22 01:10

Sam