Learn iOS Development UI article--nsnotificationcenter Notification Center

Source: Internet
Author: User
Tags notification center

Nsnotificationcenter can achieve a greater span of communication mechanisms than Delegate, which can communicate with two non-referencing two objects. The Nsnotificationcenter communication principle uses the observer pattern;

1. Nsnotificationcenter registered observers are interested in an event (named after a string) and the Selector or Block that is executed when the event is triggered

  2. Nsnotificationcenter the event at a certain time (named by string)

3. The observer performs the corresponding Selector or Block when receiving an event of interest

To use notification hubs:

1. Registered Observer

[[Nsnotificationcenter defaultcenter] addobserver:self                                         selector: @selector (selector)                                             name:@ "  notification_name"                                           object: nil";

2. Triggering events (publishing broadcasts)

[[Nsnotificationcenter Defaultcenter] Postnotificationname:@ "notification_name"                                                    Object: nil];

3. The selector method is automatically executed by the Observer

4. Cancel the listener when you do not want to listen (be sure to do it while the object is destroyed)

generally unregister before the listener is destroyed (such as by adding the following code to the listener):-(void) dealloc {    [[Nsnotificationcenter Defaultcenter] Removeobserver:self];}

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.