KVO - How to get a list of an objects registered observers

心已入冬 提交于 2019-12-22 04:34:14

问题


I am registering an observer on a bunch of tableview controllers dynamically so I need to remove previous observers if they were registered on the same object. To do this I need to check if the observer exists on the object.

Is this possible? I know with NSNotification you can use the NSNotification center singleton but is this the same for KVO?


回答1:


No, there is no simple way that I'm aware of. KVO and NSNotification differs in that matter. Why don't you implement your solution with NSNotification instead of KVO if you need that functionality?




回答2:


I dont know, how can you remove observers registered on the same objects.

But i think below method will help you to move little ahead to find your solution.

observationInfo

Returns a pointer that identifies information about all of the observers that are registered with the receiver.

- (void *)observationInfo

The default implementation of this method retrieves the information from a global dictionary keyed by the receiver’s pointers.



来源:https://stackoverflow.com/questions/10684160/kvo-how-to-get-a-list-of-an-objects-registered-observers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!