views:

103

answers:

2

I have a series of UITableViewCell elements with various UIControls to set model values.

When I make a change to model, I am having difficulty finding a way to update the UITableViewCell that displays the calculated property from the model.

I have placed the model in AppDelegate, and accessing it directly from RootViewController. In each UITableViewCell implementation I have a method that updates the model when a change is made.

But then, I am not sure how to refresh the display to show the update. (I tried connecting the same element to two actions. But, the order in which the actions are completed is not consistent, so it first reloads the display, then updates the model).

Any help would be highly appreciated.

Thanks..

A: 

If you're using a NSFetchedResultsManager, it's pretty easy to implement the delegate callbacks to your UITableViewController. Specifically:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller;
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath;
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type;
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller;

Take a look at the RootViewController in the Core Data Books example for the implementation.

In this way, you aren't doing a complete reload of the data, you're just modifying the parts that changed.

Matt B.
+1  A: 

I tried connecting the same element to two actions. But, the order in which the actions are completed is not consistent, so it first reloads the display, then updates the model

Try using only one action, that first updates the model and when that is done, updates the display. It seems to me that your problem is synchronizing these two, so I suggest looking into calling the display-updating function after your model-updating function.

luvieere
Thanks Luvieere,The UITableViewCell has the setModel function, and the update function should be called in RootViewController. Do I create a RootViewController variable in UITableViewCellController Object, and call the updateDisplay method on that ?Is this the right approach?
Prasanna
Either that, or have your RootViewController update function static, so you could call it like [RootViewController update].
luvieere