سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top