hzxu
hzxu

Reputation: 5823

NSNotificationCenter: removeAllObserver for self works for several observing objects?

Say if I have several:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(notificationReceived:)
                                                 name:NotificationA
                                               object:self.player];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(notificationReceived:)
                                                 name:NotificationB
                                               object:self.player];

The objects are all self.player but for different notifications, in the end I do:

[[NSNotificationCenter defaultCenter] removeObserver:self];

Is this fine or do I have to use the full method to remove observer for each notification? Currently I'm having issue when the view controller is unloaded but player is still playing in background.

Thanks

Upvotes: 0

Views: 134

Answers (1)

Reinhard Männer
Reinhard Männer

Reputation: 15247

The docs say: "removeObserver: Removes all the entries specifying a given observer from the receiver’s dispatch table." So your method call is enough.

Upvotes: 2

Related Questions