nsnotification--Notification Pass Value

Source: Internet
Author: User

Nsnotification

Recently do exercise project found in a UIView without controller puch to Uiviewcontroller, need to use the notification value

The notification value is a one-to-many value-transfer method;

Notification hubs can pass values across multiple pages, usually from a later page to the previous page. Idea: The value of the third interface is passed to the first interface. 1. In the first interface to establish a notification center, through the Notification Center, register a listener event 2. In the first interface, set up events to receive notifications. 3. In the first interface in the Dealloc, remove the notification center, be sure to remove the notification, otherwise it will cause memory leaks; 4. In the required interface, establish a notification center, through the Notification center, send notifications (the process of sending notifications is the process of transmitting value, the value to be transferred as the value of object to the first interface code: in the first interface

// Add a dictionary to Pass the value of the label through the key value setting

nsdictionary *dict =[[nsdictionary alloc] initwithobjectsandkeys: [nsstring stringWithFormat:@ "%d", (int) abtn. Tag],@ "Abtn.tag", Nil];

// Create a notification

nsnotification *notification =[nsnotification notificationwithname:@ "Puch" Object:nil userInfo:d ICT];

// send notifications via notification hubs

[[nsnotificationcenter defaultcenter] postnotification: notification];

To remove a notification:

[[Nsnotificationcenter Defaultcenter] removeobserver:observer name:nil object:self];

On the required interface:

// registration Notice

[[nsnotificationcenter defaultcenter] addobserver:self selector:@ Selector(Tongzhi:) name:@ "Puch" object:nil];

-(void) Tongzhi: (nsnotification *) puch{

NSLog(@ "%@", Puch. UserInfo[@ "Abtn.tag"]);

NSLog(@ "toreceive notification ------");}

Http://www.cnblogs.com/lmyailgs/p/4460791.html

nsnotification--Notification Pass Value

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.