title: Objective C: Using tags
body: <p>I've been researching for the past few days and can't figure this out. I have a lot of buttons that do the same thing (disappear when clicked). I define each one with its own tag, but how do I determine which one is pressed? </p>
  
  <pre><code>-(IBAction) tapBrick{
  int x = brick.tag;
  NSLog(@"%d", x);
  
  
  //remove last brick
  [brick removeFromSuperview];
  
  //add to score
  count++;
  NSString *scoreString = [NSString stringWithFormat:@"%d", count];
  score.text = scoreString;
  
  //determine x y coordinates
  int xPos, yPos;
  xPos = arc4random() % 250;
  yPos = arc4random() % 370;
  }
  
  
  -(void) produceBricks {
  //determine x y coordinates
  int xPos, yPos;
  xPos = arc4random() % 250;
  yPos = arc4random() % 370;
  
  //create brick
  brick = [[UIButton alloc] initWithFrame:CGRectMake(xPos,yPos + 60,70,30)];  
  [brick setBackgroundColor:[UIColor blackColor]];
  [brick setTag:i];
  [brick addTarget:self action:@selector(tapBrick) forControlEvents:UIControlEventTouchUpInside];
  i++;
  [self.view addSubview:brick];
  
  
  }
  </code></pre>
  
  <p>Produce Bricks is called every 2 seconds by a timer. </p>