Endokun
Endokun

Reputation: 13

Tapping UIButton in custom cell doesn't call didSelectRowAtIndexPath

I have a UIButton in a custom cell that I programmatically added:

UIButton *tag = [[UIButton alloc] init];
[tag addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

And this is my button handler:

-(void)buttonClicked:(id)sender
{
    UIButton *clickedButton= (UIButton*)sender;
    NSLog(@"Button tapped!", nil);
    self.tagTapped = YES;
    self.tagSelected = clickedButton.titleLabel.text;
}

The button tap is registered, but didSelectRowAtIndexPath in my master view controller is not being called. Tapping elsewhere in the cell works, but tapping on the button does not call the method. Any ideas?

Upvotes: 0

Views: 799

Answers (1)

John Sauer
John Sauer

Reputation: 4421

Tapping elsewhere in the cell works, but tapping on the button does not call the method (didSelectRowAtIndexPath).

That's by design. Most people use UIButtons to do something different than what occurs when the user selects the row. For example, when browsing voicemails in Apple's Phone app, tapping the row enables the Call Back & Delete buttons, while tapping the row's blue AccessoryDetailDisclosureButton displays a new ViewController showing the voicemail's date & phone number.

Upvotes: 1

Related Questions