Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在managedObjectcontext中注销对象?_Iphone_Xcode_Nsmanagedobject - Fatal编程技术网

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:)