问题
So, I think that when I click outside of a popover, the method popoverControllerDidDismissPopover
should be called. I know this isn't called when dismissPopoverAnimated
is called.
I have a simple project that I have setup that shows popoverControllerDidDismissPopover
just isn't called:
#import "ViewController.h"
#import "PopoverViewController.h"
@interface ViewController ()
{
PopoverViewController *controller;
UIPopoverController *popoverController;
}
@end
@implementation ViewController
@synthesize button;
- (IBAction)showPopover:(UIButton *)sender
{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake(self.button.frame.origin.x,
self.button.frame.origin.y,
self.button.frame.size.width,
self.button.frame.size.height);
[popoverController presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
controller = [[PopoverViewController alloc] initWithNibName:@"PopoverViewController" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(@"Why am I never called!!!!");
}
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return true;
}
@end
Please tell me where I'm going wrong or how I can detect when a popover is dismissed.
The whole project is here:
https://rapidshare.com/files/3182903825/PopoverDemo.zip
回答1:
You never set the delegate
for your popoverController
to self
.
_popoverController.delegate = self;
回答2:
You didn't set the delegate
of your popoverController
. Add the following code to the end of the viewDidLoad
method:
popoverController.delegate = self;
来源:https://stackoverflow.com/questions/16672108/popovercontrollerdiddismisspopover-not-doing-what-i-think-it-should