gpt4 book ai didi

ios - 使用 Firebase 数据在 TableViewCell 中实现共享按钮

转载 作者:行者123 更新时间:2023-11-29 05:57:34 24 4
gpt4 key购买 nike

我正在尝试在 TableViewCell 中实现共享按钮,该按钮使用文本和图像的数据。该代码工作完美,但我希望动态使用 TableViewCell 中的数据。

@IBAction func tapShareButton(_ sender: UIButton) {
//Shoename should be the releasename
let firstActivityItem = "Find out everywhere the *shoename* is available to purchase"
let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")!
// Image should be the releaseimage
let image : UIImage = UIImage(named: "image.jpg")!

let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem, image], applicationActivities: nil)

activityViewController.popoverPresentationController?.sourceView = (sender )
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)

// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivity.ActivityType.postToWeibo,
UIActivity.ActivityType.print,
UIActivity.ActivityType.assignToContact,
UIActivity.ActivityType.saveToCameraRoll,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.postToFlickr,
UIActivity.ActivityType.postToVimeo,
UIActivity.ActivityType.postToTencentWeibo
]

self.presentViewController(activityViewController, animated: true, completion: nil)
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "ReleaseCell", for: indexPath) as! ReleaseTableViewCell
var release: ReleaseModel
release = releasesData[indexPath.row]

cell.releaseType.text = release.releasetype
cell.releaseName.text = release.releasename
cell.releaseDate.text = release.releasedate
cell.releaseImage.sd_setImage(with: URL(string: release.releaseimage!), placeholderImage: UIImage(named: "placeholder1"))

cell.delegate = self
return cell
}

最佳答案

使用按钮位置获取单元格的索引路径,然后从模型对象中提取特定数据。

编辑:

您可以在 UIActivityViewController 中直接将图像与文本一起共享,因为如果图像在 url 中,则需要在共享之前下载图像,否则您可以通过将其保存在数组中来直接共享。

@IBAction func tapShareButton(_ sender: UIButton) {

//Get the button position in the tableView
let buttonPosition = sender.convert(CGPoint.zero, to: self.tableView)

//Find the indexPath of tableView from the button position
if let indexPath = self.tableView.indexPathForRow(at:buttonPosition) {

//Extract release from data at particular indexPath
let newRelease = releasesData[indexPath.row]

//Shoename should be the releasename
let firstActivityItem = newRelease.releasename///"Find out everywhere the *shoename* is available to purchase"


let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")!
// Image should be the releaseimage
let image : UIImage = newRelease.releaseimage

let activityViewController : UIActivityViewController = UIActivityViewController(
activityItems: [firstActivityItem, secondActivityItem, image], applicationActivities: nil)

activityViewController.popoverPresentationController?.sourceView = (sender )
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)

// Anything you want to exclude
activityViewController.excludedActivityTypes = [
UIActivity.ActivityType.postToWeibo,
UIActivity.ActivityType.print,
UIActivity.ActivityType.assignToContact,
UIActivity.ActivityType.saveToCameraRoll,
UIActivity.ActivityType.addToReadingList,
UIActivity.ActivityType.postToFlickr,
UIActivity.ActivityType.postToVimeo,
UIActivity.ActivityType.postToTencentWeibo
]

self.present(activityViewController, animated: true, completion: nil)
}
}

关于ios - 使用 Firebase 数据在 TableViewCell 中实现共享按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54994632/

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