我正在尝试添加一个按钮,以便在 Twitter、Facebook 等中分享一些句子。这一切都适用于所有 iPhone 型号,但模拟器在 iPad 上崩溃。
这是我的代码:
@IBAction func shareButton(sender: AnyObject) {
frase = labelFrases.text!
autor = labelAutores.text!
var myShare = "\(frase) - \(autor)"
let activityVC: UIActivityViewController = UIActivityViewController(activityItems: [myShare], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
这是错误:
由于未捕获的异常“NSGenericException”而终止应用程序,原因:“UIPopoverPresentationController(<_uialertcontrolleractionsheetregularpresentationcontroller>)应该在演示发生之前设置一个非零的sourceView或barButtonItem
我该怎么解决呢?
对于 ipad (iOS > 8.0),您需要设置 popoverPresentationController:
//check ipad
if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
//ios > 8.0
if ( activityVC.respondsToSelector(Selector("popoverPresentationController"))){
activityVC.popoverPresentationController?.sourceView = super.view
}
}
self.presentViewController(activityVC, animated: true, completion: nil)
更多信息请点击这里:UIActivityViewController 在 iOS 8 iPad 上崩溃 https://stackoverflow.com/questions/25644054/uiactivityviewcontroller-crashing-on-ios8-ipads
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)