views:

669

answers:

3
- (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.

+2  A: 

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

NSInteger i = [sender tag];
Rob
A: 

You can simply call:

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

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

fbrereto
There's no need to cast, since the id type will accept any method signature without complaining.
Dave DeLong
Thanks Dave - I'm aware of that, I'm doing to only for my own benefit in tracing what I assign/use. As soon I'll get better in tracking the object that I use/create I'll stop that useless practice.
amok
If it's for visual tracing only, it's cleaner to just end the line with a comment (like ` // UIView*`) instead.
Quinn Taylor
A: 

Robs suggestion worked great for me, thanks

Peter Johnson