我有一个通过 NSFetchedResultsController 填充的 UITableView。当用户向右滑动一个项目时,我会出现一个删除按钮,以便他/她可以使用以下方法删除该对象:
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//perform similar delete action as above but for one cell
XMPPUserCoreDataStorageObject *user = [[self fetchedResultsController] objectAtIndexPath:indexPath];
NSLog(@"User delete: %@", [user displayName]);
//delete from fetchController
NSArray *sections = [[self fetchedResultsController] sections];
int userStatus = [[user sectionNum] intValue];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
但是当我这样做时会出现一个异常,因为我没有更新我的 fetchedResultsController 模型。问题是如何使用我从 commitEditingStyle 获得的 indexPath 从 fetchedController 中删除?