我有一个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 =正确下载它们的字符串......
... 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
}
如果有人能帮我解决这个问题,我会提前感谢你!
最好的问候。
答案 0 :(得分:0)
您可以添加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)
}