UIView中的Swift共享表单



我有一个类与UIView和想要共享一个URL链接,什么是在UIView中添加共享表的正确方法?

我当前的代码试图通过一个按钮点击调用共享表:

//share app
@IBAction func shareAppBtn(sender: AnyObject ) {
    print("shareAppBtn tapped")
    let myWebsite = NSURL(string:"http://www.google.com/")
    guard let url = myWebsite else {
        print("nothing found")
        return
    }
    let shareItems:Array = [url]
    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    self.window?.rootViewController!.presentViewController(activityViewController, animated: true, completion: nil)
}

我试图使用当前UIView的根视图,但我收到一个错误:

Warning: Attempt to present <UIActivityViewController: on <RAMAnimatedTabBarController.RAMAnimatedTabBarController: which is already presenting <SideMenu.UISideMenuNavigationController: Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController:)

谢谢。

你不能在UIView中添加共享表单。共享表单是一个视图控制器,因此它总是需要另一个视图控制器来提供显示的上下文。

你已经通过使用当前视图的根视图做到了这一点,它已经呈现了一个导航控制器UISideMenuNavigationController

试着从上下文中呈现:

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

最新更新