Go:IOS Notification Notification Center
: nsnotification
1. Notification Hubs overview
Notification hubs are essentially a mechanism for providing message broadcasts within a program. Notification hubs cannot communicate between processes. is actually a setter that forwards the message to the desired object, based on the internal message forwarding. Notification hubs is based on the observer pattern, which allows you to register and delete observers.
A nsnotificationcenter can have a lot of notification messages nsnotification, for each nsnotification can have a lot of observers observer to receive notifications.
2. Notification hubs two important classes
Nsnotificationcenter: This is the soul of the notification hub in iOS, which implements the observer pattern and provides the developer with an interface such as registering and deleting the observer, and we can use a singleton to get an example of it (note, There is only one Nsnotificationcenter instance object inside a program).
Nsnotification: This is the carrier of the message, through which the message content can be passed to the observer. Where: Name corresponds to the message name designation. object is usually the sender itself, dictionary is the message content that is passed.
3. How notification hubs are used
Through, we can see that the use of notification hubs can be divided into 4 steps.
What you need to mention here is that sending a message can be more than just a user-initiated or a system-initiated.
When we register the observer for a message, if we have the corresponding message, the observer receives the corresponding message and expands the processing. It is important to note that when you finish using the message, you do not want to receive the message, you need to remove the observer, otherwise an error will occur.
Registration Notice: Where to accept the message
[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (mytest:) name:@ "PostData" object:nil];
Parameter Description:
Addobserver: The Observer, where the notification is received;
Selector: What method is called after receiving the notification, that is, the callback function;
Name: The name of the notification, which is also the only indication of the notification, which the compiler will use to find the notification.
Send notification: Invokes the method at the Observer.
[[Nsnotificationcenter Defaultcenter] postnotificationname:@ "PostData" Object:searchfriendarray];