Class: NSNotificationCenter
Overview
An NSNotificationCenter object (or simply, notification center) provides a mechanism for broadcasting information within a program. An NSNotificationCenter object is essentially a notification dispatch table.
Class Method Summary (collapse)
-
+ defaultCenter
Returns the process’s default notification center.
Instance Method Summary (collapse)
-
- addObserver:selector:name:object:
Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender.
-
- addObserverForName:object:queue:usingBlock:
Adds an entry to the receiver’s dispatch table with a notification queue and a block to add to the queue, and optional criteria: notification name and sender.
-
- postNotification:
Posts a given notification to the receiver.
-
- postNotificationName:object:
Creates a notification with a given name and sender and posts it to the receiver.
-
- postNotificationName:object:userInfo:
Creates a notification with a given name, sender, and information and posts it to the receiver.
-
- removeObserver:
Removes all the entries specifying a given observer from the receiver’s dispatch table.
-
- removeObserver:name:object:
Removes matching entries from the receiver’s dispatch table.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) defaultCenter
Returns the process’s default notification center.
Instance Method Details
- (Object) addObserver(notificationObserver, selector:notificationSelector, name:notificationName, object:notificationSender)
Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender. Be sure to invoke removeObserver: or removeObserver:name:object: before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated.
- (Object) addObserverForName(name, object:obj, queue:queue, usingBlock:block)
Adds an entry to the receiver’s dispatch table with a notification queue and a block to add to the queue, and optional criteria: notification name and sender. If a given notification triggers more than one observer block, the blocks may all be executed concurrently with respect to one another (but on their given queue or on the current thread).The following example shows how you can register to receive locale change notifications.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 by addObserverForName:object:queue:usingBlock: is deallocated.
- (Object) postNotification(notification)
Posts a given notification to the receiver. You can create a notification with the NSNotification class method notificationWithName:object: or notificationWithName:object:userInfo:. An exception is raised if notification is nil.
- (Object) postNotificationName(notificationName, object:notificationSender)
Creates a notification with a given name and sender and posts it to the receiver. This method invokes postNotificationName:object:userInfo: with a userInfo argument of nil.
- (Object) postNotificationName(notificationName, object:notificationSender, userInfo:userInfo)
Creates a notification with a given name, sender, and information and posts it to the receiver. This method is the preferred method for posting notifications.
- (Object) removeObserver(notificationObserver)
Removes all the entries specifying a given observer from the receiver’s dispatch table. Be sure to invoke this method (or removeObserver:name:object:) before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated.The following example illustrates how to unregister someObserver for all notifications for which it had previously registered:
- (Object) removeObserver(notificationObserver, name:notificationName, object:notificationSender)
Removes matching entries from the receiver’s dispatch table. Be sure to invoke this method (or removeObserver:) before the observer object or any object specified in addObserver:selector:name:object: is deallocated.