0

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

Dave Chambers
  • 2,483
  • 2
  • 32
  • 55

3 Answers3

3

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.

R3D3vil
  • 681
  • 1
  • 9
  • 22
0

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

Roman Temchenko
  • 1,796
  • 1
  • 13
  • 17
  • Thanks. I think that would have worked but I made some errors and got confused. In the end this wasn't appropriate for the class structure I had – Dave Chambers May 21 '13 at 16:52
0

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

Marioea
  • 201
  • 2
  • 5
  • Great idea. I tried this but somehow I am still getting more than one popover displayed at once!! – Dave Chambers May 21 '13 at 15:10
  • Where/How do you store that flag? it seems that it is possibly losing its value or it is not setting to 'TRUE' correctly – Marioea May 21 '13 at 15:38
  • I'm working on a solution. Some of the other answers have good points but it somehow seems iOS recognises an additional touch BEFORE I can disallow a second popover. I think it's a timing issue – Dave Chambers May 21 '13 at 15:41
  • try the "self.popUpPresent = TRUE;" inside of the 'init' method of your popUp...could help if it is a timing issue – Marioea May 21 '13 at 15:48