gpt4 book ai didi

ios - 检测弹出窗口关闭

转载 作者:可可西里 更新时间:2023-11-01 03:25:25 25 4
gpt4 key购买 nike

我想玩 UIPopupController,我知道我无法检测到弹出窗口何时关闭。我的步骤:
1. 从 XCode 创建示例 (File -> New Project -> Utilitiy Application)
2.在MainViewController.h中添加UIPopoverControllerDelegate

#import "FlipsideViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UIPopoverControllerDelegate>

@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;

- (IBAction)showInfo:(id)sender;

@end
  1. 在主视图 Controller 中:
    - (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");    }

但是当我点击某处,弹出窗口消失时,控制台中没有 NSLog 消息。我做错了什么?

最佳答案

将弹出窗口的委托(delegate)设置为自己,您也可以使用两个弹出窗口委托(delegate),即:-

 /* 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 - 检测弹出窗口关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10319392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com