0
votes

I am trying to delete an image and a string from core data. I have a UITableView and when you click on a cell, it takes you to a deletedViewController there is a button to delete the items in the cell from core data as well as delete the cell from the table view.

Here is the code I am using:

//Delete Photo
NSManagedObject *objectToBeDeleted = [self managedObject]; // Replace this with whatever you use to reference the managed object
NSManagedObjectContext *context = [objectToBeDeleted managedObjectContext];
[context deleteObject:objectToBeDeleted];

[self.navigationController popViewControllerAnimated:YES];
2

2 Answers

1
votes

Are you using fetchresultcontroller? The deletion will be performed finally when you call

[context save:&error];

And the fetchresultcontroller delegate will be called after this save to update the table view cells.

0
votes

Code looks fine..

I will suggest if you use breakpoint to check the managedObject you are sending to deleteViewController is same as one you are deleting.