UITableView does not call didSelectRowAtIndexPath function when I click button in UITableViewCell

I have button which has radio button as image in a UITableViewCell. When I click that button it turn into checked radio button or unchecked radio button. That is working but the problem is that it does not trigger didSelectRowAtIndexPath. It only triggers that function when I click free place on row. I have tried UITapGestureRecognizer but it also does not work. How can I fix this?

Thanks for the help.

Upvotes: 0

Views: 687

Answers (2)

Yasir Ali
Yasir Ali

Reputation: 154

you can create a delegate in your tableview cell class and implement it in the view controller, that delegate should return the indexpath. when you create the tableview cell, pass the indexpath to it. now when the segment bar is tapped and its method is called, you can call the delegate and pass the indexpath to it. as you implemented the delegate in the view controller, you can then manually call table.didselectrowatindexpath with the indexpath returned in the delegate in the view controller. Hope this clears out the logic for you!

Upvotes: 1

Rajesh73
Rajesh73

Reputation: 342

Based on my understanding, you want to have same functionality on both Button and row selection,

If its true, Some Ways I know,

  1. Do manually call the didSelectRowAtIndexPath method on Button Event.

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:ROW_YOU_WANT_TO_SELECT inSection:SECTION_YOU_WANT_TO_SELECT]
    [self tableView:YOUR_TABLE didSelectRowAtIndexPath:indexPath];
    

    and have your functionality in didSelectRowAtIndexPath.

  2. Remove the action targets from Button and have TapGestureRecogniser on cell.

Upvotes: 2

Related Questions