title: UICollectionView Drag and Drop update all affected indexPaths
body: <p>I have a <code>UICollectionView</code> that uses drag and drop functionality to perform manual re-order of the cells.<br>
  I only have 1 section that contains two columns of equally sized cells.<br>
  To explain my problem properly I would need to upload screenshots but I don't have enough rep, so I will have to explain using numbers.</p>
  
  <p>1 2 3 4 5 6  </p>
  
  <p>This represents a <code>CollectionView</code> with 6 cells in 2 columns filling the entire screen.<br>
  So the problem i'm encountering is that if I swap, for example, cell 3 and cell 2 everything works correctly because cell 3 becomes cell 2 and vice versa, the issue happens when I swap cell 3 and cell 1 because then cell 3 becomes cell1 and cell1 becomes cell2 and cell2 becomes cell3.<br>
  Now it re-arranges but as soon as the app calls <code>[self.collectionView reloadData];</code>  cell3 will stay at 1 where I dropped it, but the new cell 2 and 3 will swap positions as if there indexes havn't updated.  </p>
  
  <p>A long press gesture handles the remove and insert of the cell(snapshot of cell) when dragged and all the tiles re-arrange and fit properly into the sections.  </p>
  
  <pre><code>-(IBAction)longPressGestureRecognized:(id)sender {
  
  UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
  UIGestureRecognizerState state = longPress.state;
  
  CGPoint location = [longPress locationInView:self.collectionView];
  NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];
  
  static UIView *snapshot = nil;
  static NSIndexPath *sourceIndexPath = nil;
  
  switch (state) {
      case UIGestureRecognizerStateBegan: {
          if (indexPath) {
              sourceIndexPath = indexPath;
  
              UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
              snapshot = [self customSnapshotFromView:(cell)];
  
  
              __block CGPoint center = cell.center;
              snapshot.center = center;
              snapshot.alpha = 0.98;
              [self.collectionView addSubview:snapshot];
              [UIView animateWithDuration:0.25 animations:^{
  
                  center.y = location.y;
                  snapshot.center = center;
                  snapshot.transform = CGAffineTransformMakeScale(1.05, 1.05);
                  snapshot.alpha = 0.98;
  
                  cell.hidden = YES;
              } completion:nil];
          }
          break;
      }
      case UIGestureRecognizerStateChanged: {
          CGPoint center = snapshot.center;
          center.y = location.y;
          center.x = location.x;
          snapshot.center = center;
  
          if (indexPath &amp;&amp; ![indexPath isEqual:sourceIndexPath]) {
              [people2 exchangeObjectAtIndex:indexPath.item withObjectAtIndex:sourceIndexPath.item];
              [self.collectionView moveItemAtIndexPath:sourceIndexPath toIndexPath:indexPath];
              sourceIndexPath = indexPath;
              [databaseClass arrangeData:people2];
          }
          break;
      }
      default: {
          UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:sourceIndexPath];
          [UIView animateWithDuration:0.25 animations:^{
  
              snapshot.center = cell.center;
              snapshot.transform = CGAffineTransformIdentity;
              snapshot.alpha = 0.0;
              cell.hidden = NO;
  
          } completion:^(BOOL finished){
              [snapshot removeFromSuperview];
              snapshot = nil;
  
  
  
          }];
          sourceIndexPath = nil;
          break;
      }
  }
  }
  </code></pre>
  
  <p>I am using a sqlite method to store the arrangement of the tiles in the database.  </p>
  
  <pre><code>+(void)arrangeData:(NSArray*)arrange {
  
  [self databaseInit];
  
  if (sqlite3_open(dbpath, &amp;peopleDB ) == SQLITE_OK)
  {
      for (int i = 0; i &lt; [arrange count]; i++) {
          NSString *insertSQL = [NSString stringWithFormat:@"UPDATE PEOPLE SET ARRANGE = %i WHERE ID = %i",i+1,[[arrange objectAtIndex:i] ID]];
  
          const char *insert_stmt = [insertSQL UTF8String];
          sqlite3_prepare_v2( peopleDB, insert_stmt,-1, &amp;statement, NULL);
          if (sqlite3_step(statement) == SQLITE_DONE)
          {
              NSLog(@"Arranged Successfully");
  
          }
          else {
              NSLog(@"%s SQLITE_ERROR '%s' (%1d)", __FUNCTION__, sqlite3_errmsg(peopleDB), sqlite3_errcode(peopleDB));
  
          }
          sqlite3_finalize(statement);
      }
     sqlite3_close(peopleDB);
  }
  </code></pre>
  
  <p>Not that it matters much but the snapshot :</p>
  
  <pre><code>-(UIView *)customSnapshotFromView:(UIView *)inputView {
  UIView *snapshot = [inputView snapshotViewAfterScreenUpdates:YES];
  snapshot.layer.masksToBounds = NO;
  snapshot.layer.cornerRadius = 0.0;
  snapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0);
  snapshot.layer.shadowRadius = 5.0;
  snapshot.layer.shadowOpacity = 0.4;
  
  return snapshot;
  }   
  </code></pre>
  
  <p>If anyone has any ideas on how to get the cells to stay where they are when the longpress ends I would be hugely appreciative.</p>