gpt4 book ai didi

ios - 选择 UITableViewCell 内的图像

转载 作者:行者123 更新时间:2023-11-30 13:39:21 25 4
gpt4 key购买 nike

我有一个 tableView,该 tableView 内部有 3 个图像。

我希望能够选择一个图像并定向到另一个 VC,在其中显示已点击的图像。

对于我的图像(从 Parse 下载),我有一个 uuid(唯一标识符),之前当我使用 collectionView 时,我将其设置如下:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
postuuid.append(uuidArray[indexPath.row])

let post = self.storyboard?.instantiateViewControllerWithIdentifier("collectionImage") as! CollectionImageViewController
self.navigationController?.pushViewController(post, animated: true)
}

这让我得到了我现在想要实现的目标......

我意识到我不能使用 TableView SelectedRow..... 因为这显然会选择整行,所以我设置了一个图像 UITapGestureRecognized,如下所示:

 let imageTap = UITapGestureRecognizer(target: self, action: "imageTap")
imageTap.numberOfTapsRequired = 1
imageView.userInteractionEnabled = true
imageView.addGestureRecognizer(imageTap)

然后使用 func() 将其重定向到新的 VC:

 func imageTap() {

postuuid.append// My issues here, I'm not sure how to set it up or reference it to the cellForRow, like I did it in the collectionViewSelected item code above.

let post = self.storyboard?.instantiateViewControllerWithIdentifier("collectionImage") as! CollectionImageViewController
self.navigationController?.pushViewController(post, animated: true)
}

正如您从我的代码中看到的那样,我不知道,或者目前似乎无法弄清楚,如何将其连接到唯一 ID...

我将 UUID 设置为 var = uuidArray = String ,它正在正确下载它们...

CellForRow...:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var counter = (indexPath.row * 3)

let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! ProfileTableViewCell




for imageView in cell.threeImages {
imageView.image = UIImage(named: "ImagePlaceHolder")

if counter < imageArray.count {
imageView.hidden = false
let finalImage = imageArray[counter++]["image"]
finalImage!.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
imageView.image = UIImage(data:imageData)

}}}} else {
imageView.hidden = true
}



let imageTap = UITapGestureRecognizer(target: self, action: "imageTap")
imageTap.numberOfTapsRequired = 1
imageView.userInteractionEnabled = true
imageView.addGestureRecognizer(imageTap)


return cell
}

如果有人可以帮助我解决这个问题,我提前非常感谢!

致以诚挚的问候。

最佳答案

您可以添加indexPath.row作为tapGesture识别器的标签:

...
let imageTap = UITapGestureRecognizer(target: self, action: "imageTap:")
imageView.tag = indexPath.row
...

并将您的函数设置为

func imageTap(sender:AnyObject) {

postuuid.append(uuidArray[sender.view.tag])

let post = self.storyboard?.instantiateViewControllerWithIdentifier("collectionImage") as! CollectionImageViewController
self.navigationController?.pushViewController(post, animated: true)
}

关于ios - 选择 UITableViewCell 内的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35745810/

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