显示UIPopOverPresentationController时崩溃

时间:2015-11-25 14:44:30

标签: ios swift crash uipopovercontroller

***由于未捕获的异常终止应用程序' NSGenericException',原因:' UIPopoverPresentationController(< _UIAlertControllerActionSheetRegularPresentationController:0x1a56bd90>)应该在演示文稿发生之前设置非零的sourceView或barButtonItem 。'

2 个答案:

答案 0 :(得分:0)

self.dismissViewControllerAnimated(true, completion: nil)
        let textToShare:String = "Lets have a chat!";
        let activityVC:UIActivityViewController = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil)
        let excludeActivities = [UIActivityTypeAirDrop, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypeAssignToContact, UIActivityTypePostToFlickr, UIActivityTypePostToTencentWeibo, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo]
        activityVC.excludedActivityTypes = excludeActivities
        activityVC.modalPresentationStyle =  UIModalPresentationStyle.FormSheet
 presentViewController(activityVC, animated: true, completion: nil)

答案 1 :(得分:0)

我使用以下代码修改并找到了解决方案。

if (DeviceType.IS_IPAD == false)
{
    presentViewController(activityVC, animated: true, completion: nil)
}else {
    // Change Rect to position Popover
    let popUp = UIPopoverController(contentViewController: activityVC)
    popUp.presentPopoverFromRect(CGRectZero, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}