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

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

问题描述

所以我注意到在iOS上测试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和警报视图上不太明显,因为Apple实际上创建了一个单独的窗口,一个空的视图控制器,并在其上面显示内部的 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.

作为一种解决方法,我建议使用以下方法将演示文稿延迟到下一个runloop:

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天全站免登陆