1

所以,我认为当我在弹出框之外单击时,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

4

2 回答 2

2

你从来没有设置delegate你的popoverControllerto self

_popoverController.delegate = self;
于 2013-05-21T14:07:57.877 回答
1

你没有设置delegate你的popoverController. 将以下代码添加到viewDidLoad方法的末尾:

popoverController.delegate = self;
于 2013-05-21T14:08:53.890 回答