iPad使用UIAlertControllerStyleActionSheet错误处理

iPad使用UIAlertControllerStyleActionSheet容易掉坑里,先看错误信息:

*** Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘Your application has presented a UIAlertController (<UIAlertController: 0x7ff87f7f4f60>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller’s popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem.  If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.’

发生错误的代码如下:

 

解决的代码:

在iPad中需要设置popoverPresentationController的sourceView、sourceRect、方向。

 

http://stackoverflow.com/questions/26039229/swift-uialtertcontroller-actionsheet-ipad-ios8-crashes

尊重原创内容,转载请注明出处
本文链接地址: http://www.awnlab.com/archives/194

为您推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注