3
votes

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 ?

1
may be you have added a view over cell and that's absorbing your toches over cell. It's just a hypothesis. - rptwsthi
It should be working fine if you added the target and action to the button. It should not pass the touch event to the cell if you tap the button. IS user interaction enabled? - Nikola Kirev
@kyuubi- are button are taking action...? - Vivek Sehrawat
@Kyuubi - Post You code...We cant guess much - Vivek Sehrawat
Why a custom cell subview in cell?? I didn't get that! - Meera

1 Answers

8
votes

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