|
WebObjects 5.4.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.webobjects.foundation.NSNotificationCenter
public class NSNotificationCenter
An NSNotificationCenter object (or simply, notification center) is essentially a notification dispatch table. It notifies all observers of notifications meeting specific criteria. This information is encapsulated in NSNotification objects, also known as notifications. Client objects register themselves as observers of specific notifications posted by other objects. When an event occurs, an object posts an appropriate notification to the notification center. The notification center dispatches a message to each registered observer, passing the notification as the sole argument. It is possible for the posting object and the observing object to be the same.
There is a single notification center instance which can be accessed with the defaultCenter
static method.
There are two ways to register to receive notifications:
addOmniscientObserver
method specifying the method the notification should invoke on the observeraddObserver
method, specifying the method the notification should invoke, and one or both of the name of the notification the observer wants to receive, and which object notifications it
receives should contain. If the observer specifies only the object, it will receive all notifications containing that object. If the observer specifies only a notification name, it will receive that notification every time it's posted, regardless of the object associated with it. If both are
specified, the observer will receive all of the notifications with that name and associated with the objectNote: If the default NSNotificationCenter is the last object in your application with a reference to either an object registered to receive notifications or an object being observed, that object will be garbage collected.
NSNotification
,
NSNotificationCenter.defaultCenter()
,
NSNotificationCenter.addOmniscientObserver(Object observer, NSSelector sel)
,
NSNotificationCenter.addObserver(Object observer, NSSelector sel, String name, Object object)
Constructor Summary | |
---|---|
protected |
NSNotificationCenter()
Standard no-arg constructor. |
Method Summary | |
---|---|
void |
addObserver(Object observer,
NSSelector sel,
String name,
Object object)
Registers observer to receive notifications with the name name and/or containing object . |
void |
addOmniscientObserver(Object observer,
NSSelector sel)
Registers observer to receive all notifications from all objects. |
static NSNotificationCenter |
defaultCenter()
Return the single instance of NSNotificationCenter, which should be used for registering all notifications. |
void |
postNotification(NSNotification notification)
Posts notification to the notification center. |
void |
postNotification(String notificationName,
Object notificationObject)
Creates a notification with the name notificationName , associates it with the object notificationObject , and posts it to the notification center. |
void |
postNotification(String notificationName,
Object notificationObject,
NSDictionary userInfo)
Creates a notification with the name notificationName , associates it with the object notificationObject and dictionary userInfo , and posts it to the notification center. |
void |
removeObserver(Object observer)
Removes observer as the observer of notifications from the notification center. |
void |
removeObserver(Object observer,
String name,
Object object)
Removes observer as the observer of notifications with the name name and object object from the notification center. |
void |
removeOmniscientObserver(Object observer)
Unregisters observer as an observer of all notifications. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected NSNotificationCenter()
Method Detail |
---|
public static NSNotificationCenter defaultCenter()
public String toString()
toString
in class Object
public void addOmniscientObserver(Object observer, NSSelector sel)
observer
to receive all notifications from all objects. When a notification is posted, the method specified by sel
is invoked on observer
with the notification as the argument.
Omniscient observers can significantly degrade performance and should be used with care.
observer
- object which will receive notificationsel
- NSSelector containing the method to be invoked when a notification is sentpublic void addObserver(Object observer, NSSelector sel, String name, Object object)
observer
to receive notifications with the name name
and/or containing object
. When a notification of name name
containing the object object
is posted, the method specified by sel
is invoked
on observer
with the notification as the argument. object
or name
can be null, but not both.
name | object | Action |
null |
null |
Do not invoke this method specifying null for both name and object . Instead, use addOmniscientObserver. |
notificationName |
anObject |
The notification center notifies the observer of all notifications with the name notficationName and object anObject . |
notificationName |
null |
The notification center notifies the observer of all notifications with the name notificationName . |
null |
anObject |
The notification center notifies the observer of all notifications with an object matching anObject . |
observer
- object which will receive notificationssel
- method that will be invoked on observer as notificationname
- notification nameobject
- notification objectNSNotificationCenter.addOmniscientObserver(Object anObserver, NSSelector aSelector)
public void removeOmniscientObserver(Object observer)
observer
as an observer of all notifications.
observer
- observer of all notificationspublic void removeObserver(Object observer)
observer
as the observer of notifications from the notification center.
observer
- observer of notificationsNSNotificationCenter.removeObserver(Object observer, String name, Object object)
public void removeObserver(Object observer, String name, Object object)
observer
as the observer of notifications with the name name
and object object
from the notification center. This method interprets null parameters as wildcards:
observer | name | object | Action |
null |
name |
object |
Removes all observers of name containing object . |
observer |
null |
object |
Removes observer as an observer of all notifications containing object . |
observer |
name |
null |
Removes observer as an observer of name containing any object. |
observer |
null |
null |
Removes all notifications containing observer . |
null |
name |
null |
Removes all observers of name . |
null |
null |
object |
Removes all observers of object . |
Recall that the object a notification contains is usually, but not always, the object that posted the notification.
observer
- object which will receive notificationname
- notification nameobject
- notification objectpublic void postNotification(NSNotification notification)
notification
to the notification center. You can create notification
with the NSNotification constructor.
notification
- notification to be propagatedpublic void postNotification(String notificationName, Object notificationObject)
notificationName
, associates it with the object notificationObject
, and posts it to the notification center. notificationObject
is typically the object posting the notification. It may be null
,
or something else entirely.
notificationName
- the notification namenotificationObject
- notificationObject that will be associated with notificationNamepublic void postNotification(String notificationName, Object notificationObject, NSDictionary userInfo)
notificationName
, associates it with the object notificationObject
and dictionary userInfo
, and posts it to the notification center.
This method is the preferred method for posting notifications. notificationObject
is typically the object posting the notification. It may be null
, or something else entirely. userInfo
also may be null
.
notificationName
- the notification namenotificationObject
- notificationObject that will be associated with notificationNameuserInfo
- user information dictionary
|
Last updated June 2008 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |