我有一个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:)
感谢。
答案 0 :(得分:0)
您不在UIView中添加共享表。共享表是一个视图控制器,因此它总是需要另一个视图控制器来提供表示的上下文。
您已使用当前视图的根视图完成此操作,该视图已呈现导航控制器UISideMenuNavigationController
。
尝试从上下文中进行演示:
sideMenuNavigationController.presentViewController(activityViewController, animated: true, completion: nil)