问题
UIPopoverController
automatically dismisses when we tap or touch outside the popoverview
.
I want to restrict this automatic popover dismissal.
回答1:
self.myPopovercontroller.passthroughViews=[NSArray arrayWithObject:self.view];
回答2:
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.
回答3:
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.
回答4:
Implement popoverControllerShouldDismissPopover:
in the delegate, and you can stop it from disappearing unless you want it to.
来源:https://stackoverflow.com/questions/6898347/disable-dismissal-of-uipopoverview-controller