Stack Overflow 上有很多关于此问题的问题和解答,但它们仅适用于 iOS 8 及之前的版本。
iOS 9 弃用了很多东西,SO 上的答案不再有效。
也就是说,我通过执行这样的转场来呈现弹出窗口
[self performSegueWithIdentifier:@"myPopover" sender:self];
这个segue是在当前viewController和popover使用的viewController之间创建的。没有涉及任何按钮。弹出窗口锚定到 View 。
问题在于 prepareForSegue:identifier
[segue destinationViewController]
是一个UIViewController
并且
[[segue destinationViewController] popoverPresentationController]
是新的UIPopoverPresentationController
并且该对象不再提供dismiss api。
相反,我们应该使用
[self dismissViewControllerAnimated:YES completion:nil];
关闭弹出窗口,但这对我没有任何影响。
我的情况是这样的:我有一个带有文本字段的弹出窗口。如果用户隐藏键盘,我想关闭弹出窗口。
所以我这样做了:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
然后
- (void)keyboardWillHide:(NSNotification *)notification {
[self dismissViewControllerAnimated:YES completion:nil];
}
但这根本没有效果。
我还尝试在弹出 View Controller 内创建一个展开转场,并从呈现的 View Controller 调用它,但这会使应用程序崩溃。
最佳答案
刚刚尝试了一下,一切似乎都很完美。
- 您的 View Controller 层次结构是什么(导航 Controller 等)?
- 您是否在呈现弹出窗口的同一 View Controller 上正确调用了
dismissViewControllerAnimated:completion:
? - 确保 subview Controller 和导航 Controller 之间没有混淆。
- 您还可以记录弹出 View Controller 的
presentingViewController
进行检查。
关于ios - 关闭 iOS 9 上由 segue 创建的 Popover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34176715/