我已经用来自服务器的一些数据填充了一个 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/