Search code examples
objective-cibaction

How to read button tag in IBAction?


I have button:

...

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
rightButton.tag = myCustomNumber;
[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
...

And here is IBAction:

..
-(IBAction)showDetails:(id)sender{

    // here I want to NSLOG button tag

}
...

How to do that?


Solution

  • Just cast your sender to UIControl

    -(IBAction)showDetails:(UIControl *)sender {
    
        // here I want to NSLOG button tag
        NSLog(@"%d",sender.tag);
    
    }