【发布时间】:2015-12-09 10:40:39
【问题描述】:
Stack Overflow 上有很多关于此的问题和答案,但它们仅适用于 iOS 8 及之前的版本。
iOS 9 弃用了很多东西,所以关于 SO 的答案不再有效。
也就是说,我通过执行这样的 segue 来呈现一个弹出框
[self performSegueWithIdentifier:@"myPopover" sender:self];
这个 segue 在当前 viewController 和 popover 使用的 viewController 之间创建。不涉及任何按钮。弹出框被锚定到一个视图。
问题在于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];
}
但这根本没有效果。
我还尝试在 popover viewController 中创建一个 unwind segue,并从呈现视图控制器中调用它,但这会使应用程序崩溃。
【问题讨论】:
-
看到这个链接可能对你有帮助stackoverflow.com/questions/28719306/…
-
@iAnurag - 你提到的问题没有告诉我我所问的......“如何解雇”不存在。
-
@Anbu.Karthik -
self presentingViewController在弹出视图控制器中给我 nil。 -
你的
keyboardWillHide:方法在哪个类?
标签: ios uipopover uipresentationcontroller