加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 当调用UIActivityViewController时,IOS 8 iPad应用程序

发布时间:2020-12-14 05:30:19 所属栏目:百科 来源:网络整理
导读:当在这个应用程序中在iPhone上调用UIActivityViewController时,它可以很好地工作,但是当在iPad上调用时,应用程序崩溃了.以下是我使用的代码: func shareButtonPress() { //when the share button is pressed,default share phrase is added,cropped image o
当在这个应用程序中在iPhone上调用UIActivityViewController时,它可以很好地工作,但是当在iPad上调用时,应用程序崩溃了.以下是我使用的代码:
func shareButtonPress() {

    //when the share button is pressed,default share phrase is added,cropped image of highscore is added

    var sharingItems = [AnyObject]()

    var shareButtonHighscore = NSUserDefaults.standardUserDefaults().objectForKey("highscore") as Int!

    sharingItems.append("Just hit (shareButtonHighscore)! Beat it! #Swath")

    UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size,false,0);
    self.view.drawViewHierarchyInRect(view.bounds,afterScreenUpdates: true)
    var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    sharingItems.append(image)

    let activityViewController = UIActivityViewController(activityItems: sharingItems,applicationActivities: nil)

    var barButtonItem: UIBarButtonItem! = UIBarButtonItem()

    activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo]

    self.presentViewController(activityViewController,animated: true,completion: nil)

}

正如您所看到的,我正在Swift中编程,在SpriteKit框架中,我不明白为什么应用程序崩溃.

我收到此错误:

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

我该怎么做才能解决这个问题?

在演示UIActivityViewController之前,添加以下代码行:
activityViewController.popoverPresentationController?.sourceView = self.view

这样,视图控制器就知道要在哪个GameViewController框架中出现.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读