本文介绍了UIAlertController:supportedInterfaceOrientations递归调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当两个警报一个接一个地出现时,我的意思是一个警报出现,而在另一个警报上,则表示另一个警报出现并且应用程序崩溃.我已经使用UIAlertController来显示警报.应用程序仅在iOS 9设备中崩溃.

When two alert present one by one, i means one alert present and over them another alert presenting and app crashing.I have used UIAlertController to display alert. App crashing only in iOS 9 device.

请在这一点上帮助我.

推荐答案

这是iOS 9中的一个错误,它无法为UIAlertController检索supportedInterfaceOrientations.在寻找UIAlertControllersupportedInterfaceOrientations时,它似乎陷入了无限递归循环(例如,它追溯到UIAlertControler-> UIViewController-> UINavigationController-> UITabBarController-> -> ...),而在源代码中实际上并未实现/覆盖对UIAlertController:supportedInterfaceOrientations的调用.

This is a bug in iOS 9 that it failed to retrieve the supportedInterfaceOrientations for UIAlertController. And it seems it dropped to an infinite recursion loop in looking for the supportedInterfaceOrientations for UIAlertController (e.g., it tracks back to UIAlertControler -> UIViewController -> UINavigationController -> UITabBarController -> UIAlertController -> ...), while the call to UIAlertController:supportedInterfaceOrientations actually is not implemented/overridden in the source code.

在我的解决方案中,我只添加了以下代码:

In my solution, I just added the following piece of code:

extension UIAlertController {     
    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
    }
    public override func shouldAutorotate() -> Bool {
        return false
    }
}

然后UIAlertController将直接返回支持的方向值,而不会无限循环.希望对您有所帮助.

Then UIAlertController will directly return the supported orientation value without infinite loop. Hope it helps.

Swift 3.0.1

extension UIAlertController {
    open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.portrait
    }  
    open override var shouldAutorotate: Bool {
        return false
    }
}

这篇关于UIAlertController:supportedInterfaceOrientations递归调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:25