只有如何更多的信息,在我来说,我有超过从NSFetchedResultsContro检索表格单元格中的图像文件来回答到敲击手势ller,所以我们需要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”方法我送的viewController的图像专用于显示轻敲图像:
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
}
}
}
这在iOS 5.0中破坏了(也许是5.0.1)。见@Andrew – bandejapaisa
答案使用一个UILabel,而不是一个UIImageView这一点也适用于iOS的5.1 – ChrisP
你表现出极大的途径。谢谢。 –