Using KVO to reload data in a UITableView

I recently expanded my horizons and try to use KVO more in my programming.

I have a view controller in my iPhone application that acts as a data source and delegate for a UITableView. I also have a singleton model controller that coordinates filling my model with data received from the Internet.

In my view of the controller, I request that the model controller download new data from the Internet. Then I can observe the singleton “dataset” property and receive KVO notifications when items are added or removed from the set.

Now each cell in my table view has an indicator that indicates whether the content in this cell has been read or not (for example, a blue “unread” dot in the mail). Like mail, when a row is selected, I will show the details of this row. In the viewDidLoad view for a detailed view, I set the read property of the object to YES. I would like the source view controller to be able to observe this “read” property of each object in the dataset so that [tableView reloadData] can be automatically called as needed and redraw cells without a blue dot.

During the study, I found the following link: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html#observingACollection

In accordance with this, it seems that I will do the following:
1) An array observer
2) Whenever I receive a notification about an array change, I add (or delete) myself as an observer for individual properties that interest me.
3) When I get a notification about a property change that interests me, I can call [tableView reloadData]

I am currently trying to implement this approach. Can anyone with experience do this, offer some advice on this approach? If this is the best way to handle this situation?

If this is the right approach, would anyone want to share their implementation of adding / removing observers for objects in the collection when the collection changes?

Thank!

+5
1

, , Core Data . , . : Ray Wenderlich,

+3

All Articles