IOS NSNotificationCenter notification center

Source: Internet
Author: User
Tags notification center

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.






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.