问题
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x1a56bd90>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
回答1:
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)
回答2:
I modified with below code and found solution.
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)
}
来源:https://stackoverflow.com/questions/33919423/crash-on-showing-uipopoverpresentationcontroller