Reputation: 1166
UIPopoverController
automatically dismisses when we tap or touch outside the popoverview
.
I want to restrict this automatic popover dismissal.
Upvotes: 1
Views: 4041
Reputation: 440
Duplicate of "is there a way NOT to have the popover dismissed when pressing outside it?"
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.
Upvotes: 5
Reputation: 1166
self.myPopovercontroller.passthroughViews=[NSArray arrayWithObject:self.view];
Upvotes: 9
Reputation: 28688
Implement popoverControllerShouldDismissPopover:
in the delegate, and you can stop it from disappearing unless you want it to.
Upvotes: 3
Reputation: 49376
Have a read of the UIPopoverController documentation. Specifically...
When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the passthroughViews property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the dismissPopoverAnimated: method as needed.
Upvotes: 3