Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton inside UITableViewCell

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 ?

like image 317
Kyuubi Avatar asked Apr 21 '26 23:04

Kyuubi


1 Answers

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

like image 81
Omar Freewan Avatar answered Apr 23 '26 16:04

Omar Freewan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!