popoverControllerDidDismissPopover不做我认为应该做的事情

时间:2013-05-21 14:06:21

标签: ios objective-c uipopovercontroller uipopover

所以,我认为当我在弹出窗口外单击时,应该调用方法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

请告诉我哪里出错了,或者我怎样才能发现当弹出被解雇的时候。

整个项目在这里:

https://rapidshare.com/files/3182903825/PopoverDemo.zip

2 个答案:

答案 0 :(得分:2)

您从未将delegate的{​​{1}}设置为popoverController

self

答案 1 :(得分:1)

您未设置delegate的{​​{1}}。将以下代码添加到popoverController方法的末尾:

viewDidLoad