title: Images in UICollectionView automatically flips when scrolled down?
body: <p>I am working with UICollectionView where I am displaying all the images from photo library of the phone.</p>
  
  <p>When I click on any of the image, the image get flipped and and some information regarding the image is displayed.</p>
  
  <p>When the user again clicks on the same image the image flips again and the original image is shown.</p>
  
  <p>The problem is that whenever I scroll down through the UICollectionView the last selected image flips automatically and the information about the image gets displayed.</p>
  
  <p>How to stop this problem.</p>
  
  <p>Here is some code:</p>
  
  <pre><code>- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
      {
          UICollectionViewCell *cell1 = [collectionView cellForItemAtIndexPath:indexPath];
          if(old_path!=NULL){
          UICollectionViewCell *cell2 = [collectionView cellForItemAtIndexPath:old_path];
          [UIView transitionFromView:cell2.selectedBackgroundView toView:cell2.contentView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
  
      }
  if(old_path==indexPath&amp;&amp;flag)
  {
    [cell1 setSelected:NO];
    [UIView transitionFromView:cell1.selectedBackgroundView toView:cell1.contentView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
      flag=FALSE;
  }
  else{
      [UIView transitionFromView:cell1.contentView toView:cell1.selectedBackgroundView duration:0.5 options:UIViewAnimationOptionCurveLinear |UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
      flag=TRUE;
  }
  old_path=indexPath;
  }
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
      ALAsset *asset = assets[indexPath.row];
      NSLog(@"Description : %@",[asset description]);
      UIImage *img=[self imageWithImage:[UIImage imageWithCGImage:[asset thumbnail]] convertToSize:CGSizeMake(150, 150)];
      UIView *contents = [[UIView alloc]initWithFrame:cell.bounds];
      contents.backgroundColor = [UIColor colorWithPatternImage:img];
  
      [cell.contentView addSubview:contents];
  
      UIView *backgroundView = [[UIView alloc]initWithFrame:cell.bounds];
      backgroundView.backgroundColor = [UIColor yellowColor];
      UIButton *del=[UIButton buttonWithType:UIButtonTypeRoundedRect];
      del.frame= CGRectMake(backgroundView.frame.origin.x+20,     backgroundView.frame.origin.y+20, 100, 40);
      [del setTitle:@"Delete" forState:UIControlStateNormal];
      [del addTarget:self action:@selector(delete) forControlEvents:UIControlEventTouchUpInside];
      [backgroundView addSubview:del];
      UIButton *cancel=[UIButton buttonWithType:UIButtonTypeRoundedRect];
      cancel.frame= CGRectMake(backgroundView.frame.origin.x+20, backgroundView.frame.origin.y+80, 100, 45);
      [cancel setTitle:@"Cancel" forState:UIControlStateNormal];
      [cancel addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
      [backgroundView addSubview:cancel];
  
      cell.selectedBackgroundView = backgroundView;
      [cell bringSubviewToFront:cell.selectedBackgroundView];
      return cell;
  }
  </code></pre>
  
  <p>Here, old_path contains the index of the last selected image.</p>