【发布时间】:2016-08-31 15:24:15
【问题描述】:
我有一个 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:)
谢谢。
【问题讨论】:
-
你为什么在 rootViewController 上调用
presentViewController?尝试不使用self.window?.rootViewController!. -
我最初确实尝试过,但是由于我是从 UIView 调用它,所以这给了我一个错误,错误是:
Use of unresolved identifier 'presentViewController' -
你必须在 viewController 上调用它,是的。你的按钮和你的 UIView 以及以某种方式在 viewController 中?
-
我的按钮在 UIView 内,由于某些原因它不能在 viewController 内。
-
也许这个帖子可以帮助你:stackoverflow.com/questions/15622736/…