UIAlertController 在ipad上crash 问题
2019-02-22 本文已影响2人
水煮杰尼龟
如果你的app Devices
没有限制iphone
,那么在你使用UIAlertController时,style设置为UIAlertControllerStyleActionSheet
,在ipad
上运行的时候则会出现crash的情况。

意思就是说: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 比较靠谱一点,没注意的话,可能上架就被打回来一次。
