开发者

KVO: Should I explicitly remove an object as an observer?

开发者 https://www.devze.com 2023-04-05 22:20 出处:网络
I have a table view controller whose cells display the content of a different object. Since the content of these objects can be updated, I use KVO to be notified of changes in order to update the tabl

I have a table view controller whose cells display the content of a different object. Since the content of these objects can be updated, I use KVO to be notified of changes in order to update the table cell view.

Now on this page Apple notes that:

The key-value observing addObserver:forKeyPath:options:context: method does not retain the observing object or the observed objects. You need to review your application’s requirements and manage retain and release for the observing, and observed, objects.

Could someone tell me what would happen if the view controller is destroyed and I haven't called r开发者_Python百科emoveObserver:forKeyPath: on each of the observed objects? Will this cause a bad access or will the framework not send the notification?


You will get a bad access error. Better to remove your controller from observers.

0

精彩评论

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

关注公众号