重新排序单元格时,iOS UITableView陷入编辑模式
当我点击编辑时,编辑模式正确输入,当我点击完成后,它正确地退出编辑模式。
但是当我拖动并重新排序单元格时,表格会陷入编辑模式,请参阅附件。唯一的办法就是杀掉应用程序。
这在iOS 6和7中很讨厌。
任何建议都将不胜感激。
- (IBAction)editAction:(id)sender
{
[self.tableView setEditing:YES animated:YES];
}
- (IBAction)doneAction:(id)sender
{
[self.tableView setEditing:NO animated:YES];
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
self.fetchedResultsController.delegate = nil;
NSMutableArray *objects = [[self.fetchedResultsController fetchedObjects] mutableCopy];
id object = [self.fetchedResultsController objectAtIndexPath:fromIndexPath];
[objects removeObject:object];
[objects insertObject:object atIndex:[toIndexPath row]];
int i = 0;
for (NSManagedObject *mo in objects) [mo setValue:[NSNumber numberWithInt:i++] forKey:@"displayOrder"];
objects = nil;
[[self currentManagedObjectContext] MR_saveToPersistentStoreAndWait];
self.fetchedResultsController.delegate = self;
[[self fetchedResultsController] performFetch:nil];
}