iphone - 从 iphone 的核心数据中删除对象时应用程序崩溃

标签 iphone ios xcode core-data

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

-(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 无法删除其他上下文中的对象’。‘任何人都可以解决这个问题吗?提前致谢

最佳答案

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

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

相关文章:

ios - 如何为所有 push segues 设置符号断点?

iphone - 如何在 iPhone 上对 WAV 文件执行 FFT?

ios - NSUserDefaults 返回之前的结果

iphone - 从 iPhone 上的流中获取 ID3 标签

ios - 使用 parse 为帖子点赞

ios - 如何修复 Swift 中的 Disappearing/Invisible/Empty UITableViewCells 问题?

iphone - 从 Storyboard 文件/NIB 文件上的控件生成的 ID 值背后的逻辑

iphone - Xcode 4.6,用作前一个参数的名称而不是选择器的一部分

iphone - 投影坐标与 iPhone OS 3.2 不同?

ios - 合适的 api 从扫描的条形码 iphone 应用程序获取产品详细信息?