美文网首页
iPad 使用 UIAlertViewController 崩溃

iPad 使用 UIAlertViewController 崩溃

作者: topws1 | 来源:发表于2019-06-22 15:33 被阅读0次
    在使用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)
    
    

    相关文章

      网友评论

          本文标题:iPad 使用 UIAlertViewController 崩溃

          本文链接:https://www.haomeiwen.com/subject/yuqvqctx.html