Iphone 如何在managedObjectcontext中注销对象?
有什么方法做这项工作吗?我在文档中找不到。如果您的意思是删除,您可以使用Iphone 如何在managedObjectcontext中注销对象?,iphone,xcode,nsmanagedobject,Iphone,Xcode,Nsmanagedobject,有什么方法做这项工作吗?我在文档中找不到。如果您的意思是删除,您可以使用[context deleteObject:object]其中context是您的NSManagedContext,而object是您的NSManagedObject派生对象。要从数据库中删除对象,请使用以下方法: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle fo
[context deleteObject:object]
其中context
是您的NSManagedContext
,而object
是您的NSManagedObject
派生对象。要从数据库中删除对象,请使用以下方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[managedObjectContext deleteObject:[userResults objectAtIndex:indexPath.row]];
[userResults removeObjectAtIndex:indexPath.row];
// Save the context.
NSError *error = nil;
if (![managedObjectContext save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self.tableView reloadData];
}
其中userResults是NSMutableArray类型,用于获取数据和存储临时值您在问什么?这没有任何意义。是否要删除对象?我认为该方法是deleteObject,thx all:)