removeObserver:
Removes all the entries specifying a given observer from the receiver’s dispatch table.
- (void)removeObserver:(id)notificationObserver
Parameters
- notificationObserver
- The observer to remove. Must not be
nil
.
Discussion
Be sure to invoke this method (or
removeObserver :name:object:
) before notificationObserver or any object specified in addObserver:selector:name:object:
is deallocated.
Example of [NSNotificationCenter removeObserver]
The following example shows how you can register to receive locale change notifications.
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; |
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue]; |
self.localeChangeObserver = [center addObserverForName:NSCurrentLocaleDidChangeNotification object:nil |
queue:mainQueue usingBlock:^(NSNotification *note) { |
NSLog(@"The user's locale changed to: %@", [[NSLocale currentLocale] localeIdentifier]); |
}]; |
To unregister observations, you pass the object returned by this method to
removeObserver:
. You must invoke removeObserver:
or removeObserver:name:object:
before any object specified byaddObserverForName:object:queue:usingBlock:
is deallocated.NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; |
[center removeObserver :self.localeChangeObserver]; |