crash on showing UIPopOverPresentationController

2019-09-02 12:39发布

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x1a56bd90>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

2条回答
再贱就再见
2楼-- · 2019-09-02 13:24

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)
}
查看更多
▲ chillily
3楼-- · 2019-09-02 13:35
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)
查看更多
登录 后发表回答