ios - 关闭时获取 UIPopoverPresentationController 事件

标签 ios objective-c uipopovercontroller dismiss

我有 viewControllerA,其中显示了显示静态数据的 UIPopoverPresentationcontroller。 请找到以下代码以获取更多信息。

- (void)openPopupScreen:(id)sender {

    PopupViewController *popupVC = [self.storyboard instantiateViewControllerWithIdentifier:@"popupViewController"];
    popupVC.delegate = self;
    popupVC.preferredContentSize = CGSizeMake(220.0f, 230.0f);
    popupVC.modalPresentationStyle = UIModalPresentationPopover;
    _popupView = popupVC.popoverPresentationController;
    self.popupView.delegate = self;
    self.popupView.sourceView = self.view;
    self.popupView.backgroundColor = [UIColor whiteColor];
    CGRect rect = CGRectMake(0.0f, 0.0f, 220.0f, 230.0f);           
    self.popupView.sourceRect = rect;
    [self presentViewController:popupVC animated:YES completion:nil];
}

因为我没有编写关闭“弹出” View 的代码,因为当我简单地触摸该 View 时它会自动关闭。

所以我的问题是我需要弹出窗口关闭时的事件。

提前致谢。

最佳答案

因为您已经使用以下语句应用了 UIPopoverPresentationControllerDelegate 的委托(delegate)。

self.popupView.delegate = self;

UIPopoverPresentationControllerDelegate 方法列表。

1) 当弹出框 Controller 关闭弹出框时调用委托(delegate)。返回 NO 以防止 //关闭 View 。

- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;

2) 当用户采取行动关闭弹出框时调用委托(delegate)。当以编程方式关闭弹出窗口时,不会调用此方法。

- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;

3) 通知委托(delegate)人即将显示弹出窗口。

- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController;

更多信息请查看 Apple Developer link .

供您引用 popoverPresentationControllerDidDismissPopover 将在您关闭弹出窗口时调用。

希望它对你有用。

关于ios - 关闭时获取 UIPopoverPresentationController 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38265378/

相关文章:

ios - Swift, SpriteKit - 暂停整个脚本

ios - 交叉构建 binutils 2.25.1 for iOS8.4 (arm64-apple-darwin14.0.0)

ios - 带阴影的 UIView - 应用 renderInContext 时速度较慢

objective-c - 如何使用 VideoToolbox 解压 H.264 视频流

ios - 为什么我的 iOS App 的 Documents 目录变成了一个文件?

objective-c - UIGestureRecognizer - 像触控板一样检测点击和拖动

ios - 如何关闭 UIPopoverController 并选择一个表格单元格?

ios - UIPopoverController presentPopoverFromRect 显示不正确

ios - 连接到已经初始化的 View Controller

ios - 如何在 xcode 5 和 ios 7 中设置默认语言环境?