Kamchatka
Kamchatka

Reputation: 3675

NSFetchedResultsController and UITableViewCell

I have a UITableViewController fetching a collection of objects A with a NSFetchedResultsController.

This works well and if these objet A's properties are updated, the UITableViewCell for A reflects the change.

The problem: this object has a relationship A->[B1, B2, B3...]. The cell is using some of the B's properties in its display. If I update one of the B's properties, the UITableViewCell doesn't reflects the change.

How can I make the cell change when I update one of the B, without reloading the whole tableview. Is there a way to mark an object to update?

Upvotes: 1

Views: 231

Answers (2)

Kamchatka
Kamchatka

Reputation: 3675

I will try James answer. I also found that using refreshObject:mergeChanges: on A would trigger reloading of this object. Is it ok to do that?

Upvotes: 0

James Huddleston
James Huddleston

Reputation: 8448

You could register for NSManagedObjectContextObjectsDidChangeNotification and examine the NSUpdatedObjectsKey value in the userInfo dictionary. If one of the updated objects is B1, B2, B3, etc., then follow its inverse relationship to determine which A object has "changed." You can determine the index of the "changed" A by finding it in NSFetchedResultsController's fetchedObjects array. And then, finally, call reloadRowsAtIndexPaths:withRowAnimation: on the UITableView.

Upvotes: 2

Related Questions