ios – 检测popover dismiss

前端之家收集整理的这篇文章主要介绍了ios – 检测popover dismiss前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想玩UIPopupController,我明白我无法检测到我的popover何时解雇.
我的步骤:
1.从XCode创建示例(文件 – >新项目 – >实用应用程序)
2.添加到MainViewController.h UIPopoverControllerDelegate
#import "FlipsideViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UIPopoverControllerDelegate>

@property (strong,nonatomic) UIPopoverController *flipsidePopoverController;

- (IBAction)showInfo:(id)sender;

@end

>在MainViewController中:


    - (IBAction)showInfo:(id)sender
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
            controller.delegate = self;
            controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:controller animated:YES];
        } else {
            if (!self.flipsidePopoverController) {
                FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil];
                controller.delegate = self;

                self.flipsidePopoverController.delegate = self

                self.flipsidePopoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
            }
            if ([self.flipsidePopoverController isPopoverVisible]) {
                [self.flipsidePopoverController dismissPopoverAnimated:YES];
            } else {
                [self.flipsidePopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            }
        }
    }

    -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    {
        NSLog(@"OLOLO");
    }

但是当我点击某个地方,并且popover消失时,Console中没有NSLog消息.
我究竟做错了什么?

解决方法

将popover的代表设置为self,你也可以使用两个popover代理,即: –
/* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
 */
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;

/* Called on the delegate when the user has taken action to dismiss the popover. This is not called when -dismissPopoverAnimated: is called directly.
 */
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController;
原文链接:/iOS/333836.html

猜你在找的iOS相关文章