Question

My app has a monthly view and for each day in the month, on a long press, a popover is displayed.

I have used self.view setExclusiveTouch:YES to prevent more than one popover occurring at once but that still occasionally allows multiple popovers.

How can I prevent more than one UIPopover from being displayed at a time?

Thanks

Was it helpful?

Solution

First of all declare a property of type UIPopoverController (lets say activePopover).

In the method that is called on long press do this:

if (self.activePopover != nil)
{
    if (self.activePopover.popoverVisible)
        [ self.activePopover dismissPopoverAnimated:YES];
    self.activePopover = nil;
}

And then when you allocate the UIPopoverController on long press assign it to activePopover. This way you always dismiss a visible popover and only then present a new one.

OTHER TIPS

You can disable any interactions outside popover by setting its passthroughViews property to empty array after its presentation.

What about a global boolean flag?

Create it as a property in a global class or in your viewcontroller and check it before opening any popup

Init it with FALSE value and when you are going to open a popup just check its value:

//In the method that handle the long press to open the popup
if(!self.popUpPresent)
{
    //open the pop up
    [self openNewPopUp];
    //put the flag
    self.popUpPresent = TRUE;
}
else
//There is a popup opened, do another stuff or nothing.

Dont forget to reset it value again to FALSE every time you close a popUp.

Hope it helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top