正确的方式来呈现活动视图控制器n iPad

时间:2015-06-22 11:52:06

标签: ios swift uipopovercontroller uiactivityviewcontroller

我正在尝试呈现活动视图控制器。它曾经在Iphone上运行良好,但显然,必须在iPad上使用popover或者应用程序崩溃。我做了以下事情:

    var sharingItems = [AnyObject]()

    if let text = sharingText {
        sharingItems.append(text)
    }
    if let image = sharingImage {
        sharingItems.append(image)
    }
    if let url = sharingURL {
        sharingItems.append(url)
    }

    let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo]
    var currentViewController:UIViewController=UIApplication.sharedApplication().keyWindow!.rootViewController!


    if respondsToSelector("popoverPresentationController") {
        let popup = UIPopoverController(contentViewController: activityViewController)
        popup.presentPopoverFromRect(CGRectMake(self.frame.size.width/2, self.frame.size.height/4, 0, 0), inView: self.view!, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
    }else{
        currentViewController.presentViewController(activityViewController, animated: true, completion: nil)
    }

但该应用程序仍然崩溃。我已经阅读了一些关于锚定它的内容,但没有成功实现它。谁知道如何解决这个问题?

编辑:

这是我得到的错误:

(< _UIAlertControllerActionSheetRegularPresentationController:0x7cf42f80>)在演示发生之前应该设置一个非零的sourceView或barButtonItem。'

0 个答案:

没有答案