所以,我认为当我在弹出窗口外单击时,应该调用方法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
请告诉我哪里出错了,或者我怎样才能发现当弹出被解雇的时候。
整个项目在这里:
答案 0 :(得分:2)
您从未将delegate
的{{1}}设置为popoverController
。
self
答案 1 :(得分:1)
您未设置delegate
的{{1}}。将以下代码添加到popoverController
方法的末尾:
viewDidLoad