上QQ阅读APP看书,第一时间看更新
Coding for KVO
There are three steps involved in setting up KVO, and one cleanup step when we have finished observing:
- We need to prepare our classes for KVO.
- We need to let the system know when we wish to observe an object, and which change(s) we wish to observe.
- We need to override NSObject's method that handles the change notification.
And when we are done, the last step:
- Let the system know that we have finished observing the object (either because we no longer need to observe changes to properties of the object, or because the observing object is to be deallocated).
Once we have done that, we will have created a fully KVO--compliant class and implemented the observation code in another class.