美文网首页
UIAlertController 在ipad上crash 问题

UIAlertController 在ipad上crash 问题

作者: 水煮杰尼龟 | 来源:发表于2019-02-22 11:34 被阅读2次

   如果你的app Devices 没有限制iphone,那么在你使用UIAlertController时,style设置为UIAlertControllerStyleActionSheet,在ipad上运行的时候则会出现crash的情况。

crash.log
意思就是说:UIAlertControllerStyleActionSheet这张style,必须提供此弹出窗口的位置信息。必须提供SourceView和SourceRect或BarButtonItem.

解决方案:

UIAlertController *alert=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//加上下面的判断
    if (alert.popoverPresentationController) {
        [alert.popoverPresentationController setPermittedArrowDirections:0];//去掉arrow箭头
        alert.popoverPresentationController.sourceView=self.view;
        alert.popoverPresentationController.sourceRect=CGRectMake(0, self.view.height, self.view.width, self.view.height);
    }

这样处理了,和在iphone上弹出就差不了太多了。
还有一个问题:UIAlertAction 如果设置UIAlertActionStyleCancel 是不会显示的。

或者呢,Decices 还是限制为iphone 比较靠谱一点,没注意的话,可能上架就被打回来一次。
iphone

相关文章

网友评论

      本文标题:UIAlertController 在ipad上crash 问题

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