title: iOS adding tapGesture to multiple Views
body: <p>I have multiple views defined in my main view. I want to add single tap gesture to all these views. Below is the code I have written, but this registers a tap gesture to the last view that I add. So in the code below, tap is registered only for <code>messagesView</code> &amp; not for other views. I have 2 questions:</p>
  
  <ol>
  <li><p>How do I register the same tapGesture to multiple Views?</p></li>
  <li><p>Lets assume I get this working, now all single taps from these views goto the same function called <code>oneTap</code>. In this function how do I distinguish from which view the tap is coming?</p></li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>@synthesize feedsView, peopleView, messagesView, photosView;
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
      [singleTap setNumberOfTapsRequired:1];
      [singleTap setNumberOfTouchesRequired:1];
      [feedsView addGestureRecognizer:singleTap];
      [peopleView addGestureRecognizer:singleTap];
      [messagesView addGestureRecognizer:singleTap];
      //[photosView addGestureRecognizer:singleTap];
      [singleTap release];
  
      return;
  }
  </code></pre>