1

I have a UIButton on UITableViewCell and if I set

button.enabled = false;

...then subsequent clicks on that button triggers click on UITableViewCell.

So if button is disabled then how to make sure click on it won't trigger table cell click?

Praful Kadam
  • 372
  • 6
  • 22

2 Answers2

1

You can do in this way

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

     if(!cell.btn.enable)
        return;
}
Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
  • table cell should remain clickable. if button which is on cell is enable it's action sold get called and if it is disable nothing should happen. if user clicks anywhere else on cell, normal did select delegate should be called – Praful Kadam Mar 23 '15 at 09:52
  • like i said - that would be dealing with the event on a different level – codencandy Mar 23 '15 at 10:57
0

One way would be not to disable the button, but to just recognize that the button in question will not respond to touch events at the moment and do nothing in the handler for this button.

if( buttonIsActive )
{
  // trigger whatever the button was intended to trigger
}

In order to do that you would need to subclass UIButton and add a property buttonIsActive.

If you don't do it that way, i guess you will have to deal with that event on a different level (like in the handler for the UITableViewCell) or turn of gesture recognition aka selection at all (see Praful Kadam's answer).

codencandy
  • 1,701
  • 1
  • 10
  • 20