[IPhone Development] Message Communication Mechanism nsicationcenter Center

Source: Internet
Author: User

This type of program needs to be used recently. After studying it, we will share the results with you.

Nsicationicationcenter is specially set for message communication between different classes in the program, which is extremely convenient to use,

Long story short.

Set the notification, that is, where (which class) the notification is to be received, which is generally done during initialization.

[[Nsicationicationcenter defacenter center]Addobserver: Self selector: @ selector (test :)Name: @ "test"Object: Nil];

I will only describe the above parameters: addobserver is the observer, that is, where to receive notifications;

Selector: The method called after receiving the notification;

Name: This is the name of the notification and the unique identifier of the notification. The compiler will find the notification through this.

To send a notification, you must call the method at the observer.

[[Nsicationcenter center defacenter center] postnotificationname: @ "test" Object: searchfriendarray];

I will only describe the above parameters:

Postnotificationname: the name of the notification, which is the unique identifier of the notification. The compiler will find the notification through this.

Object: transmitted Parameters

The test method is called by default when a notification is sent.

-(Void)Test :( nsnotification *) Notification

{

Searchfriendarrary = [Notification object]; // get the passed object through this

}

 

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.