Use of iOS notifications

Source: Internet
Author: User

Registration: [[Nsnotificationcenter Defaultcenter] postnotificationname:@ "ChangeColor" object:self];

Reception observation: [[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (changecolor) name:@ "ChangeColor" Object:nil];

Remove the observer at Addobserver :

-(void) dealloc
{
[[Nsnotificationcenter defaultcenter]removeobserver:self];
}

Notifications are a typical observer pattern in iOS.

Observer mode in 1.iOS: notification, KVO;

2. Differences between notifications and agents:

Personally, the notice is the Observer mode, agent is the proxy mode, so the difference between the notification and agent is the difference between the two modes.

The ① observer pattern is one-to-many, mostly used for the ambiguous observer;

② notification hubs is actually a mechanism for providing message broadcasts within a program. Notification hubs cannot communicate between processes. is actually a setter that forwards the received message to the desired object, based on a message in the inner part. 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.

The principal agent (Degegate), as the name implies, entrusts something to other objects to do. Then the other object is the agent of this object, instead of it to take care of what to do . Reflected in the program, the first thing to know is the object of the client is which object, the delegate is what the content.

If there is too much notification, the management of the notification is complex, and if it is poorly managed, you will receive inexplicable messages that cannot be traced.

Use of iOS notifications

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.