title: Detect UIImageView click in UITableViewCell
body: <p>I have to make a call to specific number when imageview is clicked in tableviewcell.The number to which call is made is displayed in a label beside the imageview.But I couldn't get which cell is clicked.Always its referring to the last cell.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
  {
  
      if(cell == nil)
      {
          cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier];
          lblphone = [[UILabel alloc] initWithFrame:CGRectZero];
          lblphone.tag = 116;
          lblphone.backgroundColor = [UIColor clearColor];
          [lblphone setFont:[UIFont fontWithName:@"Helvetica" size:12]];
          [lblphone setLineBreakMode:UILineBreakModeWordWrap];
          [lblphone setUserInteractionEnabled:YES];
  
          UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)];
          tapGestureRecognizer.cancelsTouchesInView=NO;
          [tapGestureRecognizer setNumberOfTapsRequired:1];
          [lblphone addGestureRecognizer:tapGestureRecognizer];
          [tapGestureRecognizer release];
          [cell addSubview:lblphone];
  
          myImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
          myImageView.tag = 120;
          myImageView.image=[UIImage imageNamed:@"CallImg.png"];
  
          UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageSelectedInTable:)];
          [tapped setNumberOfTapsRequired:1];
          [myImageView addGestureRecognizer:tapped];
          [tapped release];
          [cell addSubview:myImageView];
      }
  
      [myImageView setFrame:CGRectMake(10, 50,30,30)];
      myImageView= (UIImageView*)[cell viewWithTag:120];
      myImageView.image=[UIImage imageNamed:@"CallImg.png"];
      myImageView.userInteractionEnabled=YES;
  
      CGSize constraint5 = CGSizeMake(320, 2000.0f);
      CGSize size5=[phone sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:constraint5 lineBreakMode:UILineBreakModeWordWrap];
      lblphone =(UILabel *)[cell viewWithTag:116];
      [lblphone setFrame:CGRectMake(45,name.frame.size.height+name.frame.origin.y,320, size5.height)];
      lblphone.textAlignment=UITextAlignmentLeft;
      lblphone.backgroundColor=[UIColor clearColor];
      lblphone.text=[NSString stringWithFormat:@"%@ ",phone ];
      [lblphone sizeToFit];
  }
  </code></pre>
  
  <p>And in the tapgesture of imageclick I am writing this :</p>
  
  <pre><code>-(IBAction)imageSelectedInTable:(UITapGestureRecognizer*)gesture
  {
      UIImageView *imgView = (UIImageView *) [gesture view];
      UITableViewCell *cell = (UITableViewCell*)[[imgView superview]superview];
      NSIndexPath *tappedIndexPath = [self.tableView indexPathForCell:cell];
      NSLog(@"Image Tap %@", tappedIndexPath);
      UILabel *phoneno = (UILabel *)[cell viewWithTag:116];
  
      NSString *phoneNumber = [@"telprompt://" stringByAppendingString:phoneno.text];
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
  }
  </code></pre>
  
  <p>But it  is always  referncing to the last cell clicked irrespective of which cell is clicked.Couldn't understand where im going wrong ?</p>