标签:blog http 使用 io for 2014 log ad
KVO使用观察者模式,监听指定的属性的变化。通常用于model层和controller层,view层通过controller层来监听model的变化。
如果有两个类BankObject, PersonObject. PersonObject的实例希望监听BankObject类的accountBalance属性
先通过addObserver:forKeyPath:options:context:方法把PersonObject实例注册为BankObject的accountBalance的观察者。这个方法只能在类的实例之间建立关联关系,而不是对类建立关联关系。
然后在PersonObject中实现observeValueForKeyPath:ofObject:change:context:方法对监听的属性进行响应。如果BankObject的accountBalance属性变化了,observeValueForKeyPath:ofObject:change:context:会被自动调用
标签:blog http 使用 io for 2014 log ad
原文地址:http://www.cnblogs.com/SuuuperPig/p/3927372.html