I have a UIImageView
inside a table cell and I added a tapGesture to it.
I want to access the UIImageView
in the handleTap method.
This is the code for the Image inside the TableCell :
func setImageForCell(cell:ImageCell, indexPath:NSIndexPath) {
var image : UIImage = UIImage(named: "brunnen1")!
cell.customImageView.userInteractionEnabled = true
cell.imageView!.tag = indexPath.row;
var tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("handleTap:"))
tapGestureRecognizer.numberOfTapsRequired = 1;
cell.customImageView.addGestureRecognizer(tapGestureRecognizer)
cell.customImageView.image = image
}
func handleTap(sender : UIView) {
// get the UIImageview from the sender, i guess ?
}
I guess I have to cast it from the UIView
?
Try this code.
func handleTap(sender : UITapGestureRecognizer) {
let imgView = sender.view as! UIImageView
// Do something.
}
Since you use a gesture recognizer, handleTap
's sender will be UITapGestureRecognizer
. The gesture recognizer has what you want.
var view: UIView? { get }
// the view the gesture is attached to. set by adding the recognizer to a UIView using the addGestureRecognizer: method
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