Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I get the tag value from the sender

- (IBAction)onClick1:(id)sender {
    // Make sure it's a UIButton
    if (![sender isKindOfClass:[UIButton class]])
        return;

    NSString *title = [(UIButton *)sender currentTitle];
}

I understand how to get the title and other current values but I don't see how I can get the value of the tag property.

like image 946
amok Avatar asked Sep 14 '09 16:09

amok


2 Answers

I've got a test project here where I just used:

NSInteger i = [sender tag];
like image 75
Rob Avatar answered Sep 19 '22 16:09

Rob


You can simply call:

NSInteger the_tag = ((UIView*)sender).tag;

Each UIButton is a subclass of UIView which contains the tag property.

like image 36
fbrereto Avatar answered Sep 23 '22 16:09

fbrereto