Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top