popoverControllerDidDismissPopover NOT doing what I think it should

大憨熊 提交于 2019-12-13 01:35:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!