为什么NSNotification中的Observer调用了两次....? [英] Why the Observer in NSNotification called twice....?
问题描述
如果类是一个自定义类,发布通知后,对应于观察者的选择器被调用两次..有更好的解决方案,所以选择器只被调用一次?
如果观察者类通过名称注册了一个通知,而不是针对特定的对象,它将接收多个消息,因为每次通知
同样,如果观察者针对特定对象注册,但不是针对命名的通知,那么每次有
被通知遥远状态变化的另一种机制是Key Value观察 - http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html
If the class is a custom class, after posting the notification, the selector corresponding to the observer is called twice.. Is there any better solution so that the selector is called only once?
If the observer class is registered for a notification by name, but not against a specific object, it will receive multiple messages, as it will be invoked every time the notification occurs, regardless of the originating object.
Likewise, if the observer is registered against a specific object, but not against a named notification, it will be messaged every time there is a notification concerning that object.
An alternative mechanism for being informed of changes in a distant state, is Key Value observing -http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html
这篇关于为什么NSNotification中的Observer调用了两次....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!