Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
- NSUInteger fromIndex = fromIndexPath.row;
- NSUInteger toIndex = toIndexPath.row;
- FFObject *affectedObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];
- affectedObject.displayOrderValue = toIndex;
- [self FF_fetchResults];
- for (NSUInteger i = 0; i < [self.fetchedResultsController.fetchedObjects count]; i++) {
- FFObject *otherObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:i];
- NSLog(@"Updated %@ / %@ from %i to %i", otherObject.name, otherObject.state, otherObject.displayOrderValue, i);
- otherObject.displayOrderValue = i;
- }
- [self FF_fetchResults];
- }
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
- NSUInteger fromIndex = fromIndexPath.row;
- NSUInteger toIndex = toIndexPath.row;
- FFObject *affectedObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:fromIndex];
- affectedObject.displayOrderValue = toIndex;
- NSUInteger start, end;
- int delta;
- if (fromIndex < toIndex) {
- // move was down, need to shift up
- delta = -1;
- start = fromIndex + 1;
- end = toIndex;
- } else { // fromIndex > toIndex
- // move was up, need to shift down
- delta = 1;
- start = toIndex;
- end = fromIndex - 1;
- }
- for (NSUInteger i = start; i <= end; i++) {
- FFObject *otherObject = [self.fetchedResultsController.fetchedObjects objectAtIndex:i];
- NSLog(@"Updated %@ / %@ from %i to %i", otherObject.name, otherObject.state, otherObject.displayOrderValue, otherObject.displayOrderValue + delta);
- otherObject.displayOrderValue += delta;
- }
- [self FF_fetchResults];
- }
- otherObject.displayOrderValue += delta;
- otherObject.displayOrderValue = [NSNumber numberWithInt:[otherObject.displayOrderValue intValue] + delta];
Add Comment
Please, Sign In to add comment