开发者

Updating UI when model is changed

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 t开发者_开发问答he model).

Any help would be highly appreciated.

Thanks..


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜