views:

33

answers:

2

Hello,

I have a UITableViewController backed by a NSFetchedResultsController.

I'm currently experiencing a SIGABRT when deleting a row, after I save the managedObjectContext in commitEditingStyle.

The crash then happens in drawRect: in my UITableViewCell where it tries to access the core-data object for this row:

[self.document.name drawAtPoint:...]

The SIGABRT exception is:

<0x7f883f0 DocumentListControllerCell.m:(108)> CoreData could not fulfill a fault 
for '0x7f2a600 <x-coredata://A71C21B4-FE2A-4D1B-A76F-A2AB80E4814C/Document/p16>'

Of course the issue is that the CoreData object has been deleted and cannot be accessed anymore. I wonder why drawRect is still called for this cell.

Any help would be appreciated!

A: 

when deleting a row also at that same time delete it from core data so that there is no redundant data that is being drawn. Happened many times to me where i delete something from the table but not from where i was fetching the data and this would crash my app as it would draw the table properly when endcommit style was called. So just make those changes and everything should be fine PK

Pavan
I do delete from CoreData:`[self.managedObjectContext deleteObject:doc];` then `[self.managedObjectContext save:`. Once you do that, the NSFetchedResultsController notifies the UITableViewController which in turns delete the row.
Kamchatka
A: 

I see one solution but I would like to know if it's the correct way to solve this problem.

The issue currently is that drawRect in the cell access the CoreData "document" which was deleted, to get the document name and draw it. Instead of doing that, I could cache the document name in a string in setDocument and directly access this string.

It seems like it would be the right way to do that. Could someone confirm that I should not access the Core Data object in drawRect ?

Kamchatka