我已经用服务器中的一些数据填充了表视图,并将其保存到核心数据。现在,当用户单击表视图中的删除选项时,我必须从核心数据中删除对象。
我尝试过的是:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSError *error;
    [[Server serverInfo].context deleteObject:[self.couponList objectAtIndex:indexPath.row]];
    if(![ [Server serverInfo].context  save:&error]) {
        // Handle error
        NSLog(@"Unresolved error series %@, %@", error, [error userInfo]);
    }
    [self.couponList removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                     withRowAnimation:UITableViewRowAnimationFade];
    if ([self.couponList count]==0) {
        [self.table setEditing:NO animated:YES];
        [self.editBt setStyle:UIBarButtonItemStyleBordered];
    }

}

`
但这会导致异常并崩溃。这是我正在登录的日志:“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'NSManagedObjectContext无法在其他上下文中删除对象”。'有人可以解决此问题吗?谢谢!

最佳答案

您必须创建一些manageobject上下文,一个获取请求,然后使用某些谓词删除对象。

关于iphone - 从iPhone的核心数据删除对象时,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10648366/

10-11 22:57
查看更多