Guest User

Untitled

a guest
Apr 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  2.  
  3. NSUInteger fromIndex = fromIndexPath.row;
  4. NSUInteger toIndex = toIndexPath.row;
  5.  
  6. FFObject *affectedObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];
  7. affectedObject.displayOrderValue = toIndex;
  8.  
  9. [self FF_fetchResults];
  10.  
  11.  
  12. for (NSUInteger i = 0; i < [self.fetchedResultsController.fetchedObjects count]; i++) {
  13. FFObject *otherObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:i];
  14. NSLog(@"Updated %@ / %@ from %i to %i", otherObject.name, otherObject.state, otherObject.displayOrderValue, i);
  15. otherObject.displayOrderValue = i;
  16. }
  17.  
  18. [self FF_fetchResults];
  19. }
  20.  
  21. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  22.  
  23. NSUInteger fromIndex = fromIndexPath.row;
  24. NSUInteger toIndex = toIndexPath.row;
  25.  
  26. FFObject *affectedObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];
  27. affectedObject.displayOrderValue = toIndex;
  28.  
  29. NSUInteger start, end;
  30. int delta;
  31.  
  32. if (fromIndex < toIndex) {
  33. // move was down, need to shift up
  34. delta = -1;
  35. start = fromIndex + 1;
  36. end = toIndex;
  37. } else { // fromIndex > toIndex
  38. // move was up, need to shift down
  39. delta = 1;
  40. start = toIndex;
  41. end = fromIndex - 1;
  42. }
  43.  
  44. for (NSUInteger i = start; i <= end; i++) {
  45. FFObject *otherObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:i];
  46. NSLog(@"Updated %@ / %@ from %i to %i", otherObject.name, otherObject.state, otherObject.displayOrderValue, otherObject.displayOrderValue + delta);
  47. otherObject.displayOrderValue += delta;
  48. }
  49.  
  50. [self FF_fetchResults];
  51. }
  52.  
  53. otherObject.displayOrderValue += delta;
  54.  
  55. otherObject.displayOrderValue = [NSNumber numberWithInt:[otherObject.displayOrderValue intValue] + delta];
Add Comment
Please, Sign In to add comment