A new understanding of Nsnotificationcenter

Source: Internet
Author: User

-(void) Postnotificationname: (NSString *) AName object: (ID) anobject userInfo: (nsdictionary *) Auserinfo; This function is post a Notification, with a anobject, with a

DIC information, nothing to say, AnObject is to send the sender of this notification.



-(void) Addobserver: (ID) Observer selector: (SEL) aselector name: (NSString *) AName object: (ID) anobject; The main thing is to understand this function is not in place, has been passed the AnObject parameter is nil, this will accept all sender sent the message.


What to do if you need to accept a change message sent by a particular object. This is the use of the AnObject parameter.


The Postnotificationname function uses the same object as the AnObject parameter of the Addobserver function, and it is OK.

For example, I need to observe a picture of the get notification, when the picture is obtained, Postnotificationname AnObject is set to the image name, and the Observer calls Addobserver, also set AnObject as the image name, This will only receive notifications for the specified image. Otherwise, all the pictures will be notified to the observer, in the acquisition of images of excessive number of scenes, will affect the efficiency.


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.