Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 522
Daniele B Avatar asked Nov 20 '22 20:11

Daniele B


1 Answers

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

like image 59
ddb Avatar answered Feb 22 '23 21:02

ddb