我需要翻译的内容是:仅仅需要额外的信息,对于我的情况来说,我需要回答关于表格单元格中图像文件上的点击手势,因此我们需要indexPath而不是行信息,所以我决定使用被点击的图像本身而不是行信息。我为该图像定义了一个变量:
var imgSelected: UIImageView? = nil
我将手势识别器添加到了imageView(imgZona)中:
public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(Storyboard.CellReuseIdentifier, forIndexPath: indexPath) as! ZonasTableViewCell
let zona = fetchedResultsController.objectAtIndexPath(indexPath) as! Zona
cell.infoZona = zona
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("imageTapped:"))
cell.imgZona?.addGestureRecognizer(tapGestureRecognizer)
cell.imgZona?.userInteractionEnabled = true
return cell
}
在 "imageTapped" 方法中,我检索了图像并保存到变量 "imgSelected" 中:
func imageTapped(sender: UITapGestureRecognizer) {
imgSelected = sender.view as? UIImageView
self.performSegueWithIdentifier("MuestraImagen", sender: self)
}
最后,在“prepareForSegue”方法中,我发送了用于显示所点击的图像的视图控制器的图像:
override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier {
case "MuestraImagen":
if let vc = segue.destinationViewController as? MuestraImagenViewController {
if imgSelected != nil {
if let img = imgSelected!.image {
vc.imgPuente = img
}
}
}
default: break
}
}
}