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
Asked
Active
Viewed 195 times
0
-
You could use a story board... – Allison May 18 '12 at 01:22
-
I'm not using storyboard though and a code would've been helpful – Big Box Developer May 18 '12 at 01:28
2 Answers
1
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…

user523234
- 14,323
- 10
- 62
- 102
0
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

Jeff
- 2,818
- 3
- 29
- 31
-
its appearing as just a blue popover. Here's my code: `PopOverView *pickerPopView = [[PopOverView alloc] init]; UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:pickerPopView]; [self.PopOverController setDelegate:self]; [self.PopOverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO]; [self.PopOverController setPopoverContentSize:CGSizeMake(320, 260)]; [self.PopOverController release];` @Jeff – Big Box Developer May 19 '12 at 01:40