4

我试图从 ios 应用程序的核心数据库中删除行但它不起作用,

if (editingStyle == UITableViewCellEditingStyleDelete) {

     appDelegate = [[UIApplication sharedApplication] delegate];   
        NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"PRODUCTTABLE" inManagedObjectContext:appDelegate.managedObjectContext];        
        NSFetchRequest *request = [[NSFetchRequest alloc] init];        
        [request setEntity:entityDesc];        
        NSError *error; 
        NSManagedObject *matches = nil;
        NSArray *objects = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
        NSLog(@"Array Count....%d",[objects count]);
        matches=[objects objectAtIndex:([indexPath row])];
        NSLog(@"...%@",[matches valueForKey:@"productID"]);
        NSLog(@"...%@",[matches valueForKey:@"pName"]);
        NSLog(@"...%@",[matches valueForKey:@"pPrice"]);
        NSLog(@"...%@",[matches valueForKey:@"pDate"]);           
        [appDelegate.managedObjectContext deleteObject:matches];


    }   

以下代码的o/p:

Array Count....12
...ABC1226
...ABC-005
...599.39
...2012-08-09 05:07:50 +0000

我正在从具有相同 NSManagedObject 的核心数据中获取数据。为什么删除不更新核心数据?

4

1 回答 1

10

更改后保存上下文。

NSError * error = nil;
[appDelegate.managedObjectContext deleteObject:matches];
[appDelegate.managedObjectContext save:&error];
于 2012-08-09T09:50:14.363 回答