iPad 使用 UIAlertViewController 崩溃

2019-06-22  本文已影响0人  topws1
在使用Alert做提示框时,在iPhone上运行正常的代码,在iPad上崩溃。

** Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x1058cf000>) of style UIAlertControllerStyleActionSheet from xxx

在崩溃的下方有崩溃解决的提示文案:
You must provide either a sourceView and sourceRect or a barButtonItem

贴上解决的代码:

if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
            if alert.responds(to: #selector(getter: popoverPresentationController)) {
                alert.popoverPresentationController?.sourceView = self.view
                alert.popoverPresentationController?.sourceRect = CGRect(x: 0, y: kScreenHeight, width: kScreenWidth, height: kScreenHeight)
            }
}
present(alert, animated: true, completion: nil)

上一篇下一篇

猜你喜欢

热点阅读