Stop UIPopover from dismissing automatically
Asked Answered
B

3

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?

Belomancy answered 20/8, 2011 at 2:30 Comment(0)
B
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

Burrus answered 20/8, 2011 at 2:40 Comment(4)
Thanks for the quick reply. 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?Belomancy
did you get this working? if so, how? if not, why is it marked as the correct answer?Thermoelectric
Did you remember to make your view controller the delegate for the popover controller?Shockproof
404 on the link, just fyiResee
D
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.

Delladelle answered 20/8, 2011 at 13:37 Comment(6)
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?Belomancy
Yes. Did you indicate implementing the UIPopoverControllerDelegate in the header file?Delladelle
I think so. In the file that contains the contents of the popover, in the .h I have protocol OptionsViewControllerDelegate <NSObject> -(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 <UITextFieldDelegate,OptionsViewControllerDelegate>{ UIPopoverController *popoverController; OptionsViewController *optionsViewController; } Then synthesize the UIpopoverController and the OptionsViewController in the .m. Am I missing anything? Thanks.Belomancy
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.Belomancy
interface exampleViewController : UIViewController <UITextFieldDelegate,OptionsViewControllerDelegate,UIPopoverControllerDelegate>Delladelle
Still no luck. (Don't feel that I'm not grateful, though, I really appreciate all your help).Belomancy
D
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

Dyedinthewool answered 21/12, 2012 at 5:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.