gpt4 book ai didi

ios - 错误 : Use of unresolved identifier 'indexPath'

转载 作者:行者123 更新时间:2023-11-29 01:02:48 24 4
gpt4 key购买 nike

我有一个打开 UIActivityViewController 的 IBAction:

@IBAction func share(sender: UIButton) {

let defaultText = "Check out my Pinpoint: " + self.pinpoints[indexPath.row].main + ". Get Pinpoint on the iOS App Store!"
if let imageToShare = UIImage(data: self.pinpoints[indexPath.row].image) {
let activityController = UIActivityViewController(activityItems: [defaultText, imageToShare], applicationActivities: nil)
self.presentViewController(activityController, animated: true, completion: nil)
}
}

错误出现在第二行和第三行(从 let defaultTextif let imageToShare 开始。)它说:

Use of unresolved identifier 'indexPath'

单词pinpoints是一个存储main(UILabel)和图像(UIImageView)的数组。

如何解决此错误?

最佳答案

只需在 cellforRowAtIndexPath 中为您的按钮提供一个标记,该标记将等于indexPath.row

someButton.tag = indexPath.row

现在你的函数应该是:

IBAction func share(sender: UIButton) { 
let defaultText = "Check out my Pinpoint: " + self.pinpoints[sender.tag].main + ". Get Pinpoint on the iOS App Store!"
if let imageToShare = UIImage(data: self.pinpoints[sender.tag].image) {
let activityController = UIActivityViewController(activityItems: [defaultText, imageToShare], applicationActivities: nil)
self.presentViewController(activityController, animated: true, completion: nil)
}
}

关于ios - 错误 : Use of unresolved identifier 'indexPath' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36813750/

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