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 selector is called twice, you've probably registered for it twice.
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
What worked for me was a couple of things:
1-In the class where the addObserver registration call is made, was to add a specific object.
2-In the class where the postNotification call is made, as the same type of object.
I also do my postNotificaiton in a dispatchAsync call as well, but that's not related to your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With