Use of iOS notification pass-through values

Source: Internet
Author: User

Notification is commonly used in the jump controller between the proxy method, in addition to proxy mode, notification is more convenient, convenient, a simple demo implementation of the notification of the jump value.

Enter the information you want to send, passing the value of the label through the button method call.

-(Ibaction) ButtonClick: (ID) Sender {

Add a dictionary to pass the value of the label through the key value setting

Nsdictionary *dict =[[nsdictionary alloc]initwithobjectsandkeys:self.textfieldone.text,@ "TextOne", self.textfieldtwo.text,@ "Texttwo", nil];

Create a notification

Nsnotification *notification =[nsnotification notificationwithname:@ "Tongzhi" object:niluserInfo:dict];

Send notifications via notification hubs

[[Nsnotificationcenter Defaultcenter] postnotification:notification];

[Self.navigationcontroller Popviewcontrolleranimated:yes];

}

After sending the notification, register the notification listener in the controller you want to receive, and send the message to receive

-(void) Viewdidload {

[Super Viewdidload];

Registration Notice

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (Tongzhi:) name:@ "Tongzhi" object:nil];

}

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

NSLog (@ "%@", text.userinfo[@ "Textone"]);

NSLog (@ "--Receive notification------");

}

Removal notifications: Removeobserver: and RemoveObserver:name:object:

Where Removeobserver: is the DELETE Notification Center saves the schedule table for all the portals of an observer, and RemoveObserver:name:object: is to delete a portal that matches the observer in the dispatch table saved by the notification center.

This is relatively straightforward, just call the method on the line. For example:

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

Note that the parameter notificationobserver is the observer to be deleted and must not be nil.

Use of iOS notification pass-through values

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.