Reputation: 19969
First time using tag attributes and wondering what I'm doing wrong here. I have two UIButtons that go to the same selector. I would like to add a tag to differentiate like this:
buttonOne.tag=1;
buttonTwo.tag=2;
In the selector that responds, I'm trying to get this tag out of the sender but being told that tag
is not found on object of type '__strong id'. I know this way is pretty hacky but is there a simple way to get this to work?
-(void)buttonClicked:(id)sender
{
NSLog(@"you were clicked with %d", (UIButton *)sender.tag);
[sender setSelected:YES];
}
thx in advance
Upvotes: 1
Views: 1604
Reputation:
Yap:
-(void)buttonClicked:(UIButton *)sender
Voila.
Or, if you're concerned to use that ugly cast, at least pay attention to operator precedence:
((UIButton *)sender).tag
Upvotes: 1