crash on showing UIPopOverPresentationController

旧城冷巷雨未停 提交于 2020-01-06 07:43:23

问题


*** 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!