Reputation: 25983
in my viewDidLoad
, I add my controller as an observer for two notifications:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:NetworkStatusChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkLocationStatus:) name:LocationStatusChangedNotification object:nil];
in my dealloc
, should I remove it once, or twice? The removeObserver method doesn't seem to specify a particular notification.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self]; // is this required?
Upvotes: 2
Views: 1007
Reputation: 10393
Documentation is the best way to clear your doubts:
The following example illustrates how to unregister someObserver for all
notifications for which it had previously registered:
[[NSNotificationCenter defaultCenter] removeObserver:someObserver];
Upvotes: 2
Reputation: 4092
From Reference:
RemoveObserver: Removes all the entries specifying a given observer from the receiver’s dispatch table.
so you need to call it only once
Upvotes: 1
Reputation: 4053
You need to remove it only once.
If you need it, you can also use -removeObserver:name:object:
to stop observing just one of the notifications.
Upvotes: 5