Daniele B Daniele B - 3 months ago 5
Swift Question

iOS: clicking on a view inside a TableCellView

I placed a small

UIView
inside a
UITableViewCell
.


  • In case of a tapping on such
    UIView
    , I would like to open a popup.

  • In case of a tapping outside such
    UIView
    , I would like to perform what it's defined in the
    UITableView
    "didSelectRowAtIndexPath" function.



What it's happening at the moment is that when I click on the view both things happen: the popup is opened and the "didSelectRowAtIndexPath" function is trigged.

How can I make sure that when I click on that
UIView
the "didSelectRowAtIndexPath" function is not triggered?

current implementation:

I defined a
UITapGestureRecognizer
for the
UIView
inside my custom
UITableViewCell
class.

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(MyCustomTableViewCell.clickOnHelp(_:)))
myClickAreaUIView.addGestureRecognizer(tapGesture)

ddb ddb
Answer

The best solution I suggest is to change the UIView to a UIButton and handle the touch with a touchUpInside on the button.

This way you will reach your objective, as UIButton automatically prevents touch event forwarding to superview