2012-08-09 3 views
4

오전 IOS 응용 프로그램에서 핵심 데이터베이스에서 행을 삭제하려고하면 다음 코드는 작동하지 않는,managedObjectContext deleteObject : 코어 데이터베이스의 데이터를 삭제하지 않습니까?

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]; 


    } 

오의/P는 꾸물 거리지 :

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

은 같은 NSManagedObject와 핵심 데이터로부터 데이터를 얻고있다 . 핵심 데이터를 삭제하지 않는 이유는 무엇입니까?

+0

변경 사항을 저장하려면 실제로 저장해야합니다. '- (BOOL) save : (NSError **) error'. –

답변

10

변경 후 컨텍스트를 저장하십시오.

NSError * error = nil; 
[appDelegate.managedObjectContext deleteObject:matches]; 
[appDelegate.managedObjectContext save:&error]; 
+0

감사합니다. 그것은 완벽하게 작동했습니다. – milesper

관련 문제