title: Custom actions for UIGestureRecognizers (with custom parameters)
body: <p><strong>Short version of my problem:</strong></p>
  
  <p>I cannot figure out how to make the "action" for my UITapGestureRecognizer take additional parameters, and actually use them.</p>
  
  <p><strong>Here's the rundown of my problem:</strong></p>
  
  <p>I am trying to make it so that my iPad app records (with NSLog) the coordinates of the UITouch that occurs whenever they press one of my app's UIButtons. The location of the touch needs to be relative to the button that was touched.</p>
  
  <p><strong>What I've done:</strong></p>
  
  <p>I have implemented a UITapGestureRecognizer and added it to each of my buttons. My problem is with the action to use, since it needs to be dynamic for each and every button.</p>
  
  <p>I currently have this code:</p>
  
  <pre><code> UITapGestureRecognizer *iconClickRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logIcon:withTag:)];
   [iconClickRecognizer setNumberOfTapsRequired:1];
   [iconClickRecognizer setNumberOfTouchesRequired:1];
   [iconClickRecognizer setDelegate:self];
   [[self.view viewWithTag:1] addGestureRecognizer:iconClickRecognizer];
  
   [iconClickRecognizer release];
  </code></pre>
  
  <p>When I know that this works, I will use a for-loop to add the iconClickRecognizer to all of the buttons by their tag.</p>
  
  <p>The <strong>logIcon:(int)withTag</strong> method is shown here:</p>
  
  <pre><code>-(void)logIcon:(UIGestureRecognizer *)gestureRecognizer withTag:(int)tag {
    NSLog(@"tag X: %f", [gestureRecognizer locationInView:(UIView*)[self.view viewWithTag:tag]].x);
    NSLog(@"tag Y: %f", [gestureRecognizer locationInView:(UIView*)[self.view viewWithTag:tag]].y);
  }
  </code></pre>
  
  <p><strong>What isn't working:</strong></p>
  
  <p>When I hard-code a tag into logIcon method, it records the information correctly. However, <strong>I do not know how to make this method dynamic</strong>, and actually use the "tag" parameter. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks,
  Alex</p>