Skip to content

Commit

Permalink
Add reloadData to avoid view hierarchy issue when reordering tasks. F…
Browse files Browse the repository at this point in the history
…ixes #80
  • Loading branch information
tonisuter committed Jan 13, 2013
1 parent 3aa5953 commit 6408f16
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions Classes/CDITasksViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -417,25 +417,25 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd


- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
if (sourceIndexPath.row == destinationIndexPath.row) {
return;
}
self.ignoreChange = YES;
NSMutableArray *tasks = [self.fetchedResultsController.fetchedObjects mutableCopy];
CDKTask *task = [self objectForViewIndexPath:sourceIndexPath];
[tasks removeObject:task];
[tasks insertObject:task atIndex:destinationIndexPath.row];
NSInteger i = 0;
for (task in tasks) {
task.position = [NSNumber numberWithInteger:i++];
}
[self.managedObjectContext save:nil];
self.ignoreChange = NO;
[CDKTask sortWithObjects:tasks];
if (sourceIndexPath.row != destinationIndexPath.row) {
self.ignoreChange = YES;
NSMutableArray *tasks = [self.fetchedResultsController.fetchedObjects mutableCopy];
CDKTask *task = [self objectForViewIndexPath:sourceIndexPath];
[tasks removeObject:task];
[tasks insertObject:task atIndex:destinationIndexPath.row];
NSInteger i = 0;
for (task in tasks) {
task.position = [NSNumber numberWithInteger:i++];
}
[self.managedObjectContext save:nil];
self.ignoreChange = NO;
[CDKTask sortWithObjects:tasks];
}

[self.tableView reloadData];
}


Expand Down

0 comments on commit 6408f16

Please sign in to comment.