title: How to add/remove uiimage in a uitableviewcell at a specific row
body: <p>in the below code i am trying to show an image on the selected row and removing the image from the previously selected row. On scrolling the tableview up and down the selected image start to appear on random rows also instead of just showing on the one selected. Can anyone here please help me fix it. I am testing this on ios7 device.
  Thanks.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  </code></pre>
  
  <p>{</p>
  
  <pre><code>static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  if (cell == nil)
  {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  
      UIImage *image = [UIImage imageNamed:@"btn_checkmark_off.png"];
      UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
      imageView.frame = CGRectMake(270, 15, 17, 17);
      imageView.tag = CELL_IMGVIEW_TG;
      [cell.contentView addSubview:imageView];
  }
  return cell;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  </code></pre>
  
  <p>{</p>
  
  <pre><code>if (self.prevRowIndex != indexPath.row)
  {
      NSIndexPath *pPrevIndexPath = [NSIndexPath indexPathForRow:self.prevRowIndex inSection:indexPath.section];
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:pPrevIndexPath];
      UIImageView* pImgView = (UIImageView*)[cell.contentView viewWithTag:CELL_IMGVIEW_TG];
      pImgView.image = [UIImage imageNamed:@"btn_checkmark_off.png"];
      // update index
      self.prevRowIndex = indexPath.row;
  
  }
  UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  UIImageView* pImgView = (UIImageView*)[cell.contentView viewWithTag:CELL_IMGVIEW_TG];
  pImgView.image = [UIImage imageNamed:@"btn_checkmark_on.png"];
  </code></pre>
  
  <p>}</p>