Today, let's take a look at the nsicationicationcenter message and notification center class.
An nsicationicationcenter object is in a program and provides a mechanism for broadcasting messages.
An nsicationicationcenter object is essentially a notification scheduling table
Every running program has a default notification center, so you generally do not need to create your own
And an nsicationicationcenter object can only deliver messages in a single project
If you want to deliver or receive notifications from other processes, you can use an NSDistributedNotificationCenter instance.
The following are the methods of this class:
Notification center
+ (Id) defaultCenter // return the default notification center of the current process
Manage Notification monitor Managing Notification Observers
-(Id) addObserverForName :( NSString *) name object :( id) obj queue :( NSOperationQueue *) queue usingBlock :( void (^) (NSNotification *) block
// Add an event monitor, the name of the event to be monitored, and the object to be notified by obj.
// Queue
// You must call removeObserver: Or removeObserver: name: object: to remove the created monitor before you destroy it.
-(Void) addObserver :( id) notificationObserver selector :( SEL) icationicationselector name :( NSString *) notificationName object :( id) notificationSender
// Add an event monitor called icationicationobserver
// Icationicationselector the method called when the monitored event occurs
// Icationicationname parameter attached to the notification received by icationicationsender
// Same as above. You must remove an object created using this method before it is destroyed.
-(Void) removeObserver :( id) notificationObserver
// Remove all events to be monitored by a monitor.
-(Void) removeObserver :( id) notificationObserver name :( NSString *) notificationName object :( id) notificationSender
// Remove the specified monitor and notification
Publish notification Posting Notifications
-(Void) postNotification :( NSNotification *) notification
// Publish a specified notification
-(Void) postNotificationName :( NSString *) notificationName object :( id) notificationSender
// Create a notification with the specified name and release it
-(Void) postNotificationName :( NSString *) notificationName object :( id) icationicationsender userInfo :( NSDictionary *) userInfo
// The same as above. Only the notification information is added, that is, the notification information in the last parameter dictionary can be blank.
The above is the entire content of the notification center.
I think the most important thing in the notification center is the one-to-many relationship, that is, sending notifications in one place can respond in multiple places at the same time,
Even though messages can be transmitted through delegation, the delegation is a one-to-one relationship,
This notification center will be used in projects. A typical case is to send a notification when the subject is changed.
It is very convenient to receive the notification and change it accordingly.
Okay. Here we will share some of the main content of this class with you-LC.