Iphone managedObjectContext deleteObject:不从核心数据库删除数据的匹配项?
我试图在ios应用程序中从核心数据库中删除行,但它不起作用Iphone managedObjectContext deleteObject:不从核心数据库删除数据的匹配项?,iphone,ios,core-data,nsmanagedobjectcontext,Iphone,Ios,Core Data,Nsmanagedobjectcontext,我试图在ios应用程序中从核心数据库中删除行,但它不起作用 if (editingStyle == UITableViewCellEditingStyleDelete) { appDelegate = [[UIApplication sharedApplication] delegate]; NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"PRODUCTTABLE" i
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从核心数据中获取数据。为什么删除而不更新核心数据?更改后保存上下文
NSError * error = nil;
[appDelegate.managedObjectContext deleteObject:matches];
[appDelegate.managedObjectContext save:&error];
您必须实际保存以保留更改<代码>-(BOOL)保存:(n错误**)错误。