IPhone IOS 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,

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

[[NSNotificationCenter
defaultCenter] 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.

[[NSNotificationCenter
defaultCenter] 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

}

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.