当我删除 tableView 中的一行时,我希望选择它上面的行。这不会发生...
这是代码:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
if (indexPath.section == 0) {
Formula *toDelete = (Formula *)[self.userFRMList objectAtIndex:indexPath.row];
NSManagedObjectContext *context = (NSManagedObjectContext *)[(PSAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSError *error = nil;
[context deleteObject:toDelete];
[context save:&error];
[self updateDataSource];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
if ([self.userFRMList count] != 0) {
if (indexPath.row == 0) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
self.crtFormula = [self.userFRMList objectAtIndex:0];
[self.delegate theFormulaIs:self.crtFormula];
} else {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section] animated:YES scrollPosition:UITableViewScrollPositionNone];
self.crtFormula = [self.userFRMList objectAtIndex:indexPath.row - 1];
[self.delegate theFormulaIs:self.crtFormula];
}
}else {
self.crtFormula = nil;
[self.delegate showBlank];
}
[tableView endUpdates];
}
}
}