iPad warning:Attempt to present
2017-05-08 本文已影响0人
Just丶Go
这个问题网上也有很多的答案.我在这里分享下我详细过程.
设备: ipad pro
系统:iOS 10.3
相关代码
这里使用actionSheet 创建活动卡<问题就出现在这>
![](https://img.haomeiwen.com/i2571591/0688e92c3522e6f7.png)
...
![](https://img.haomeiwen.com/i2571591/2b0247ec9dff6b3f.png)
// 这里
![](https://img.haomeiwen.com/i2571591/19e69ee6c003feb5.png)
正确的代码
__weak typedef(self)weakSelf = self;
if([[[UIDevicecurrentDevice]systemVersion]floatValue]>=8.0){
[[NSOperationQueuemainQueue]addOperationWithBlock:^{[selfpresentViewController:cameraUI animated:NO completion:nil];}];
}else{
[controller presentViewController:cameraUI animated:NO completion:nil];
}
原因分析:
![](https://img.haomeiwen.com/i2571591/a2e6738730a3580c.png)
提供答案的作者猜想,在ios 8 中, alert view 和 action sheet 实际上是以控制器的方式弹出的.所以,如果你从这个alert view 上弹出了一个响应控制器的话,这时,这个alert view 正在销毁, 而 你要弹出的控制器却整在被弹出. 操作冲突. 所以我延迟了 UIImagePickerController 的弹出, 直到runloop的下一次迭代.
笔者第一次写分享,写的不是很好,很多东西怕自己了解的不够深,造成误解.所以都是直接找的准确的解答来分享.