【发布时间】:2016-02-19 07:54:28
【问题描述】:
swift: how to get the indexpath.row when a button in a cell is tapped?
此链接是点击按钮时的答案,如果我的问题是不可能的,我将只使用一个按钮并将图像放在上面。我只是想知道是否可以通过点击UIImageView 而不是按钮来实现这一点。我用UIImageView 而不是UIButton 尝试了确切的答案,我得到了这个错误
“致命错误:在展开可选值时意外发现 nil”。
cell.imagePosted 是UIImageView
let tapGR = UITapGestureRecognizer(target: self,action:Selector("imageTapped:"))
cell.imagePosted.userInteractionEnabled = true
cell.imagePosted.addGestureRecognizer(tapGR);
func imageTapped(img: AnyObject)
{
if let imgView = img as? UIImageView {
if let superView = imgView.superview {
if let cell = superView.superview as? CellCustom {
indexPath2 = self.tableView.indexPathForCell(cell)
}
}
}
print(indexPath2.row)
}
【问题讨论】:
标签: ios swift uitableview uiimageview