所以,我认为当我在弹出框之外单击时,popoverControllerDidDismissPopover
应该调用该方法。我知道在调用时不会调用dismissPopoverAnimated
它。
我有一个简单的项目,我已经设置了显示popoverControllerDidDismissPopover
只是没有被调用:
#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
请告诉我哪里出了问题,或者我如何检测弹出框何时被解除。
整个项目在这里: