Question

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

Was it helpful?

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…

OTHER TIPS

Quick way to do it is to define a UIPopOverController property in your presenting view controller and use this property to instantiate your popover (and accompanying content view controller).

In your presenting view controller you'll need something like:

UIViewController *aViewController = [[UIViewController alloc]init];
self.popOverController = [[UIPopoverController alloc] initWithContentViewController:aViewController]; 

Then in your button's action to toggle the popOver it should do something like:

    if(self.popOverController.popoverVisible) {
    [self.popOverController dismissPopoverAnimated:YES];
    } else { //Display the popover }

Hope that help

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