重新排序单元格时,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];
}