Reputation:
I have designed a UITableViewCell
in a .xib. The cell contains an UIImageView
that only partially covers the cell. The behavior I am seeking is, if the user taps on the UIImageView
, the UIImageView
's UITapGestureRecognizer
's selector gets triggered, and the UITableViewCell
does not trigger didSelectRowAtIndexPath
. If the user taps on the UITableViewCell
but not the UIImageView
, then I want the opposite behavior. Right know what I'm getting is, when the user taps on the UIImageView
, both the UITapGestureRecognizer
's selector and didSelectRowAtIndexPath
get triggered. And when the user taps on just the UITableViewCell
, everything works fine. How can I get the desired behavior? I have tried messing around with cancelsTouchesInView
among other things.
Upvotes: 0
Views: 818
Reputation: 954
You don't need to use gesture recognizer to the cell, instead allow userInteractionEnabled set to true for the imageView and add target to the imageView. Refer to this code:
yourImageView.userInteractionEnabled = true
let tapGesture = UITapGestureRecognizer(target: self, action: "imageTapped")
yourImageView.addGestureRecognizer(tapGesture)
Upvotes: 1