在 iOS8 - iOS11 中从动作表的委托模态呈现视图控制器 [英] Presenting a view controller modally from an action sheet's delegate in iOS8 - iOS11

查看:11
本文介绍了在 iOS8 - iOS11 中从动作表的委托模态呈现视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我注意到在 iPad 上的 iOS8 beta 3(更新:仍然发生在 iOS 11.2)中,当尝试从 UIActionSheet,什么都没有"发生,并且一条日志消息输出到调试控制台,说明在转换警报控制器时尝试了演示:

So I noticed that in iOS8 beta 3 (Update: still happens in iOS 11.2) on iPad, when attempting to present a view controller from within a delegate method of a UIActionSheet, "nothing" happens and a log message is output to the debug console, stating that presentation was attempted while transitioning an alert controller:

Warning: Attempt to present <UIViewController: 0x...> on <ViewController: 0x...> which is already presenting <UIAlertController: 0x...>

推荐答案

更新: 从 iOS 9 SDK 开始,UIActionSheet 已被弃用,因此不要指望修复这个问题.最好尽可能开始使用 UIAlertController.

Update: As of iOS 9 SDK, UIActionSheet is deprecated, so do not expect a fix regarding this issue. It is best to start using UIAlertController when possible.

问题似乎来自 Apple 切换到在内部使用 UIAlertController 来实现警报视图和操作表的功能.该问题主要出现在 iPad 和操作表上,因为在 iPad 上,操作表在指定视图中显示为弹出框,Apple 所做的是遍历响应者链,直到找到视图控制器并调用 presentViewController:animated:completion: 与内部 UIAlertController.这个问题在 iPhone 和警报视图上不太明显,因为苹果实际上创建了一个单独的窗口、一个空视图控制器并在其上显示内部 UIAlertController,所以它似乎不会干扰其他演示文稿.

The problem seems to come from Apple's switch to using UIAlertController internally to implement the functionality of alert views and action sheets. The issue is seen mostly on iPad and action sheets, because on iPad, action sheets are presented as a popover within a specified view, and what Apple does is travel the responder chain until it finds a view controller and calls presentViewController:animated:completion: with the internal UIAlertController. The problem is less obvious on iPhone and with alert views, because there Apple actually creates a separate window, an empty view controller and presents the internal UIAlertController on top of that, so it seems to not interfere with other presentation.

我已打开此问题的错误报告:rdar://17742017.请复制它并让 Apple 知道这是一个问题.

I have opened bug report for this issue: rdar://17742017. Please duplicate it and let Apple know this is a problem.

作为一种解决方法,我建议使用以下方法将演示延迟到下一个运行循环:

As a workaround, I recommend delaying the presentation until the next runloop, using the following method:

dispatch_async(dispatch_get_main_queue(), ^ {
    [self presentViewController:vc animated:YES completion:nil];
});

这篇关于在 iOS8 - iOS11 中从动作表的委托模态呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆