当在这个应用程序中在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.'
我该怎么做才能解决这个问题?