3

I have 2 UIButtons inside a myCustomCell Class which is a subclass of UITableViewCell.

My Custom Cell

The black Outline is the cell (UITableViewCell *) which is returned by 'cellForRowAtIndex'. This cell contains 'myCustomCell' as a subview. 'myCustomCell' has two UIButtons and the following properties :

    backgroundcolor = clearColor 
    opaque = NO

On clicking anywhere in the cell except for the two Red Boxes(UI Buttons), I want the 'didSelectRowAtIndexPath' be triggered. But if the user clicks on the UIButton, only the selector for the target needs to be triggered, and not the 'didSelectRowAtIndexPath'. How can I achieve this ?

Kyuubi
  • 1,228
  • 3
  • 18
  • 32

1 Answers1

8

if you build the cell as you mentioned above : the myCustomCell represent a subview inside the cell and it has two buttons inside it, each button has action, this should work as following; when you click on the button the didSelectRowAtIndexPath will not work and the button will handle the touch event since the touch hierarchy will be observed by the first action wich is the button and will not continue to the didSelectRowAtIndexPath and when you tab every where except buttons the didSelectRowAtIndexPath will handle the touch since there no observer handle this touch event and it will reach the didSelectRowAtIndexPath

Omar Freewan
  • 2,678
  • 4
  • 25
  • 49
  • I had set myCustomCell.userInteractionEnabled = NO , So that the labels and other unnecessary elements do not block the touch for the 'didSelectRowAtIndexPath'. Upon setting this property to 'YES', the touch triggers the correct selectors. But the various elements are now blocking the 'didSelectRowAtIndexPath'. – Kyuubi Jun 25 '13 at 06:46