title: UICollectionView not redrawing cells when inserted at position where cells were deleted before
body: <p>I am making a UICollectionView control which would look like (fig-1) :</p>
  
  <p>I have added the ability to delete cell by swiping the cells to right.</p>
  
  <p>My problem case - If I delete the last cell by swiping (fig-2) , which will call the following code.</p>
  
  <pre><code>- (void)removeTheCell:(AnyObject *)obj {
  
      // remove the object
      NSIndexPath *indexPath = [NSIndexPath indexPathForItem:[self.allObjects indexOfObject:obj] inSection:0];
  
      [self.allObjects removeObjectAtIndex:indexPath.row];
  
  
      [self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
  }
  </code></pre>
  
  <p>And then add a new cell with different color using following method (fig-4):</p>
  
  <pre><code>- (void)addNewObject:(NSNotification *)notification {
  
      NSDictionary *dict = notification.userInfo;
      NSArray *newObjects_a = [dict objectForKey:ALL_OBJECTS];
  
      NSMutableArray *indexArrays = [[NSMutableArray alloc] init];
      for (AnyObject *obj in newObjects_a) {
          [self.allObjects addObject:obj];
          [indexArrays addObject:[NSIndexPath indexPathForItem:[self.allObjects indexOfObject:obj] inSection:0]];
      }
  
  
      [self.collectionView performBatchUpdates:^{
  
          [self.collectionView insertItemsAtIndexPaths:indexArrays];
  
      } completion:nil];
  
  }
  </code></pre>
  
  <p>The cell that is displayed still looks like the old deleted cell with its last state (fig-4). But i checked the data source it doesn't contain the deleted object. It contains the latest data.</p>
  
  <p>(fig-5)If i change to list layout by selecting the segment control which call the following method:</p>
  
  <pre><code>- (IBAction)SwitchCellFrames:(id)sender {
  
      int selection = ((UISegmentedControl *)sender).selectedSegmentIndex;
  
      isGridView = selection == 0 ? YES : NO;
  
      if (isGridView) {
          [self.collectionView setCollectionViewLayout:gridFlowLayout animated:YES];
      }else {
          [self.collectionView setCollectionViewLayout:listFlowLayout animated:YES];
      }
  
  }
  </code></pre>
  
  <p>layout variables are defined as :</p>
  
  <pre><code>    gridFlowLayout = [[UICollectionViewFlowLayout alloc] init];
      [gridFlowLayout setItemSize:CGSizeMake(160, 155)];
      [gridFlowLayout setMinimumInteritemSpacing:0.0f];
      [gridFlowLayout setMinimumLineSpacing:0.0f];
      [gridFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
  
  
      listFlowLayout = [[UICollectionViewFlowLayout alloc] init];
      [listFlowLayout setItemSize:CGSizeMake(320, 80)];
      [listFlowLayout setMinimumInteritemSpacing:0.0f];
      [listFlowLayout setMinimumLineSpacing:0.0f];
      [listFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
  </code></pre>
  
  <p>The collectionView now updates the new cell with the right color (fig-5/fig-6).</p>
  
  <p>I tried <code>[self.collectionView setNeedsDisplay]</code> / <code>[self.collectionView setNeedsLayout]</code> / <code>[self.collectionView reloadData]</code>. These are not causing the UI to redraw itself.</p>
  
  <p>I don't know what is causing the UICollectionView to retain the deleted view. Please Help.</p>
  
  <p><img src="https://i.stack.imgur.com/ytlrs.png" alt="enter image description here"></p>