gpt4 book ai didi

swift - UIActivityView 按钮错误

转载 作者:行者123 更新时间:2023-11-30 12:55:46 24 4
gpt4 key购买 nike

我正在尝试使用 UIActivityView 为我的应用程序创建共享按钮。当我按下应用程序中的按钮时,出现错误。代码有什么问题?

@IBAction func shareButton(_ sender: UIButton) {

let texttoshare = "Sharing"
let URLtoshare = NSURL(string: "www.google.com")
let objectsToShare:NSArray = [texttoshare, URLtoshare!]
let activityVC = UIActivityViewController(activityItems: objectsToShare as! [Any], applicationActivities: nil)

self.present(activityVC, animated: true, completion: nil)

}
}

错误:线程 1:信号 SIGABRT

最佳答案

试试这个。至少,它对我来说没有错误。

let texttoshare = "Sharing"
let URLtoshare = URL(string: "www.google.com")
let activityVC = UIActivityViewController(activityItems: [texttoshare, URLtoshare!], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)

如果您想在 iPad 上使用 UIActivityViewController,则需要为 activityVC 指定 popoverPresentationController?.sourceView。例如:

let texttoshare = "Sharing"
let URLtoshare = URL(string: "www.google.com")
let activityVC = UIActivityViewController(activityItems: [texttoshare, URLtoshare!], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = button...
self.present(activityVC, animated: true, completion: nil)

关于swift - UIActivityView 按钮错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40418705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com