Why did the browser at NSNotification call twice ....?

If the class is a custom class, after sending the notification, the selector corresponding to the observer is called twice. Is there a better solution so that the selector is called only once?

+5
source share
4 answers

If the observer class is registered for notification by name, but not against a specific object, it will receive several messages, as it will be called every time a notification occurs, regardless of the original object.

Similarly, if an observer is registered at a particular object, but is not against a named notification, it will be sent to the message every time there is a notification about this object.

An alternative mechanism for reporting changes in a remote state is to monitor a key value - http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html

+3
source

If the selector is called twice, you probably registered for it twice.

+8
source

, :

1 - , addObserver, .

2 - , postNotification, .

I also do my postNotificaiton in dispatchAsync call, but this is not related to your problem.

+1
source

Check if addObserver is installed only once. In my case, the addObserver loop ran twice, so the error.

0
source

All Articles