简体   繁体   English

在TableViewCell中选择图像

[英]Selecting an image inside of TableViewCell

I have a tableView, and inside of that tableView are 3 images. 我有一个tableView,并且该tableView内有3张图像。

I would like to be able to select an image and be directed to another VC where it displays the image that has been tapped. 我希望能够选择一个图像并定向到另一个VC,在该VC中它显示已点击的图像。

For my images (downloaded from Parse) I have a uuid (unique identifier), before when I was using a collectionView I set it up like this: 对于我的图像(从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)
    }

And that got me what I am trying to achieve now... 那给了我我现在想要达到的目标...

I realized I cannot use TableView SelectedRow..... as that would select the entire row obviously, so I have set up a image UITapGestureRecognized like so: 我意识到我不能使用TableView SelectedRow .....,因为那样显然会选择整个行,所以我像这样设置了一个图像UITapGestureRecognized:

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

And then a func() to redirect it to a new VC: 然后使用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)
    }

As you'll see from my code I do not know, or can't seem to figure it out at the moment, how to connect it to the unique ID... 正如您将从我的代码中看到的那样,我不知道或者目前似乎无法弄清楚如何将其连接到唯一ID ...

I have the UUID set up as var = uuidArray = String which is downloading them correctly... 我将UUID设置为var = uuidArray = String,可以正确下载它们...

CellForRow...: 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
        }

If anyone can help me with this issue, I thank you very much in advance! 如果有人可以帮助我解决这个问题,我非常感谢您!

Best regards. 最好的祝福。

You can add indexPath.row as the tag for the tapGesture recognizer: 您可以将indexPath.row添加为tapGesture识别器的标签:

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

and setup your function as 并将您的功能设置为

func imageTap(sender:AnyObject) {

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM