2

I have a table view of objects Object in an array _objects. Each object has a property status that I want to display in the table view.

My question is, how can I do this using KVO ?

I need to observe addition/removal, I think I got that working with KVO on the array itself, but I also need to observe each object's status keypath to update the table view cell.

Thomas Joulin
  • 6,590
  • 9
  • 53
  • 88

2 Answers2

0

Subclass UITableViewCell, add a property "object" and add an observer for the keypath "object.status" in the initializer or viewDidLoad of your table view cell. In "cellForRowAtIndexPath:" you'll dequeue / create the cell and set the object property.

lassej
  • 6,256
  • 6
  • 26
  • 34
0

I think you are looking for willChangeValueForKey and didChangeValueForKey methods used in KVO.

Here is a pretty good writeup this guy used to understand the same concept: http://horseshoe7.wordpress.com/2013/01/28/kvo-observing-any-change-in-object-state/

Here are some others:

http://www.andyibanez.com/74-key-value-coding-key-value-observing-and-cocoa-bindings-a-basic-tutorial

Key-Value Observing with NSMutableData iOS

Community
  • 1
  • 1
Jonathon Hibbard
  • 1,547
  • 13
  • 20