4

Am trying to delete row from core data base in ios application buts its not working,

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


    }   

the o/p for following code:

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

am getting data from core data with same NSManagedObject. why delete not updating on Core data?

Musthafa
  • 862
  • 3
  • 12
  • 27

1 Answers1

10

Save the context after changes.

NSError * error = nil;
[appDelegate.managedObjectContext deleteObject:matches];
[appDelegate.managedObjectContext save:&error];
Peter Pajchl
  • 2,699
  • 21
  • 24