iOS滑动删除单元格突然恢复正常状态

iOS滑动删除单元格突然恢复正常状态,ios,objective-c,uitableview,swipe,Ios,Objective C,Uitableview,Swipe,我正在尝试实现刷卡删除手势 有时在做了刷卡动作后,细胞会以一种强迫的方式回到正常状态。 进入编辑模式并点击-按钮,也会出现这种情况 这是随机发生的 当用户点击编辑按钮时,始终调用此方法: - (IBAction)editButtonTapped:(UIBarButtonItem *)sender { [self.tableView setEditing:!self.tableView.editing animated:YES]; } caneditrowatinexpath方法始终返回

我正在尝试实现刷卡删除手势

有时在做了刷卡动作后,细胞会以一种强迫的方式回到正常状态。 进入编辑模式并点击-按钮,也会出现这种情况

这是随机发生的

当用户点击编辑按钮时,始终调用此方法:

- (IBAction)editButtonTapped:(UIBarButtonItem *)sender {
    [self.tableView setEditing:!self.tableView.editing animated:YES];
}
caneditrowatinexpath
方法始终返回
YES
。这是我的
committedingstyle
方法:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSManagedObjectContext *context = [self managedObjectContext];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete object from database
        [context deleteObject:[self.alarmsMutableArray objectAtIndex:indexPath.row]];

        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
            return;
        }

        // Remove object from table view
        [self.alarmsMutableArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}

您需要将从模型和tableView中删除的项嵌套在更新块中 所以在最后两行代码之前

[self.tableView beginUpdates];
然后在最后把

[self.tableView endUpdates];
。。。。。。
请注意,在最后两行之间,您的模型与tableView不同步(您已从阵列中删除了一个对象,但尚未删除一个单元格…),您应该只处于[BeginUpdate]和[EndUpdate]之间的位置,否则您的应用程序可能会崩溃。

不,您不需要这样做。在多次调用
delete/insert/reloadRows
时,只需
begin/endUpdate
。此外,如果单元格在刷卡后自动恢复正常,则不会调用
CommittedItingStyle
。请查看代码中重新加载数据的任何地方,或者查看此tableview上的数据子集。很可能您有一个异步发生的通知或其他触发器,看起来是随机的。我正在withRowAnimation参数中传递UITableViewRowAnimationFade。“我不知道这是否有什么不同。”布莱顿,非常感谢!收到位置更新时,我正在调用reloadData。我的应用程序基于用户位置。