iOS:WAITING现有的过渡或演示完成

标签 ios uiviewcontroller

我认为这很简单: 每当我在应用程序运行时收到远程通知时,都会向 UIAlertController 显示消息。

问题在于,当主应用程序即将推送/显示另一个 View Controller 时,可能会显示该警报。在这种情况下,我会收到丑陋的错误消息,例如

pushViewController:animated: called on <UINavigationController 0x7f400c00> while an existing transition or presentation is occurring; the navigation stack will not be updated.

应用程序可能会以这种方式进入不一致的状态。 我怎样才能安排 View Controller 转换,使它们不会像这样发生冲突?

最佳答案

将 Controller 分成两个 UIWindow 可以解决这个问题。 您可以像这样创建一个新窗口,而不是仅仅在应用程序的 View Controller 之一上显示警报:

let screen = UIScreen.main
let screenBounds = screen.bounds
let alertWindow = UIWindow(frame: screenBounds)
alertWindow.windowLevel = UIWindowLevelAlert
let vc = UIViewController()
alertWindow.rootViewController = vc
alertWindow.screen = screen
alertWindow.isHidden = false
vc.present(alert, animated: true)

现在应用程序主窗口中的 View Controller 可以同时推送和呈现其他 Controller 以显示警报。

关于iOS:WAITING现有的过渡或演示完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780731/

相关文章:

ios - 应用程序中的自动布局 RTL 支持

python - 代码 8 : Loading a plug-in failed

ios - 适用于 iOS 的 Cordova 构建 - 未找到配置文件

ios - 通过覆盖它的指定初始化器从 Storyboard 中获取 UIVIewController

ios - 呈现具有透明背景的模态视图 Controller

ios - 从 App Delegate 呈现 View Controller

iOS UILabel 并避免使用自定义字体剪裁变音符号

ios - Xcode 6.1 消失的 UI 元素

objective-c - objective c 将一个对象设置为一个未知的类

ios - 我可以显示全屏 ViewController,但仍然可以向下滑动以返回父级(启动器)ViewController