Search code examples
iosxcodeipaduipopover

Dismissing and Opening a UIPopOver with one UIToolBarItem Button?


I was wondering how I could use 1 button on my ToolBar to open and dismiss my UIPopOver. If I keep tapping the button right now, another PopOver overlaps the previous one. I want ONE button to be able to dismiss and open my PopOver. I tap once, it opens. I tap the button again, it dismisses. Please tell me how. Thanks


Solution

  • In your button tap action event:

    if (myPopover.popoverVisible)  //self.myPopover if using property
    {
        [myPopover dismissPopoverAnimated:YES];
        return;
    }
    
    //continue code here to create/present your MyPopover…