title: iOS Gesture Handling: where to add a gesture recognizer when using a custom UIView
body: <p>I have a view controller where I display a grid/array of images, where every image view is a custom nib (custom nib because images have a name &amp; like/dislike icon too). So I displayed the grid of images doing something like this in my view controller <code>viewDidLoad</code>. </p>
  
  <pre><code>int row=0, col=0;
  for (int i=0; i&lt;arrayImg.count; i++) {
      NSArray *topObj = [[NSBundle mainBundle] loadNibNamed:@"CustomImageView" owner:nil options:nil];
      CustomImageView *imgView = [topObj objectAtIndex:0];
      imgView.frame = CGRectMake(180*col+10, 180*row+10, 170, 170);
  
      // custom image values inserted here
  
      [self.view addSubView:imgView];
  
      // update the row,col variables here
  }
  </code></pre>
  
  <p>Now I need to add a tap gesture recognizer to every image displayed on the screen. It seems logical to me to add the gesture recognizer inside the custom nib/class, <code>CustomImageView</code> in this case. <code>CustomImageView</code> extends <code>UIView</code>, so it seems a gesture recognizer cannot be declared here (auto-complete does not appear, syntax highlighting does not work either). What am I missing over here?</p>