12

I was wondering if there was a way to stop an iPad popover from dismissing automatically whenever you touch the screen outside the popover? If not, is there some kind of method similar to "popoverDidDismiss" that I could call to tell when the popover was dismissed?

Halle
  • 3,584
  • 1
  • 37
  • 53
Luke Baumann
  • 596
  • 12
  • 35

3 Answers3

27

Yes you can. This is right out of the Apple documentation.

When a popover is dismissed due to user taps outside the popover view, the popover automatically notifies its delegate of the action. If you provide a delegate, you can use this object to prevent the dismissal of the popover or perform additional actions in response to the dismissal. The popoverControllerShouldDismissPopover: delegate method lets you control whether the popover should actually be dismissed. If your delegate does not implement the method, or if your implementation returns YES, the controller dismisses the popover and sends a popoverControllerDidDismissPopover: message to the delegate.

Just return NO to the delegate method popoverControllerShouldDismissPopover:

Here is a link for further reading.

Popover Guide

Marco Santarossa
  • 4,058
  • 1
  • 29
  • 49
ms83
  • 1,804
  • 16
  • 13
4
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    return NO;
}

That does it for you and you may assign a specific bar button item or something else in your popover to dismiss the popover.

Bourne
  • 10,094
  • 5
  • 24
  • 51
  • I tried implementing this and it doesn't seem to be working. I should be putting it in the .m for the view where the popover appears, not the view inside the popover, right? – Luke Baumann Aug 21 '11 at 03:07
  • Yes. Did you indicate implementing the UIPopoverControllerDelegate in the header file? – Bourne Aug 23 '11 at 13:54
  • I think so. In the file that contains the contents of the popover, in the .h I have protocol OptionsViewControllerDelegate -(void)didPick:(NSString *)string; end id delegate; and in the .m: synthesize delegate; and in the .h of the file where the popover appears I have: interface exampleViewController : UIViewController { UIPopoverController *popoverController; OptionsViewController *optionsViewController; } Then synthesize the UIpopoverController and the OptionsViewController in the .m. Am I missing anything? Thanks. – Luke Baumann Aug 23 '11 at 20:05
  • There are also (at)s in there, but I didn't have enough characters to put them in. Sorry. If it's too confusing I can send you a text file. Thanks SO much for all your help. – Luke Baumann Aug 23 '11 at 20:06
  • interface exampleViewController : UIViewController – Bourne Aug 24 '11 at 15:09
  • Still no luck. (Don't feel that I'm not grateful, though, I really appreciate all your help). – Luke Baumann Aug 24 '11 at 21:29
1

even u can use

self.modallnpopover = yes;

if you want to dismiss it in a particular view

self.modallnpopover = no;

if you dont want to dismiss it

Craig
  • 9,335
  • 2
  • 34
  • 38
Kasaname
  • 1,491
  • 11
  • 15