I need to identify the image
that the user clicked on a TableCell
.
How to pass TAG
?
class CustomCell: UITableViewCell {
@IBOutlet weak var imgPost1: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
imgPost1.tag=1
let tap = UITapGestureRecognizer(target: self, action: #selector(CustomCell.tappedMe))
imgPost1.addGestureRecognizer(tap)
imgPost1.userInteractionEnabled = true
}
func tappedMe(xTag:Int) {
print(xTag)
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
You can use the view
property of the UIGestureRecognizer
.
Register for tap gesture:
let tap = UITapGestureRecognizer(target: self, action: "tappedMe:")
imgPost1.addGestureRecognizer(tap)
imgPost1.userInteractionEnabled = true
Now define the tappedMe method
func tappedMe(sender: UITapGestureRecognizer) {
print(sender.view?.tag)
}
PS: Don't forget to set the tag for image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With