Contact Notification Center for a long time, has not used it to pass value, today the task completed earlier, so did a small demo, after the interface Notification Center forward interface value
Sender View Controller:
-(void) Viewdidload {
[Super Viewdidload];
}
-(Ibaction) Call: (ID) Sender {
When the text in the input box is not empty
if (_atextfield.text) {
With the value of the input box as value, a as a key, stored as a dictionary
Nsdictionary *dics = @{@ "A": _atextfield.text};
Create a notification object with name two unique identifier for the controller notification
Nsnotification *notifications = [[Nsnotification alloc] initwithname:@ "abc" Object:nil Userinfo:dics];
[[Nsnotificationcenter defaultcenter]postnotification:notifications];
[Self dismissviewcontrolleranimated:yes completion:nil];
}
}
Recipient View Controller:
-(void) Viewdidload {
[Super Viewdidload];
Recipient Registration Notification Center, the name field is the same as the sender
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (ABC:) name:@ "abc" Object:nil];
}
-(void) ABC: (Nsnotification *) Notif {
_abt.text = notif.userinfo[@ "A"];
NSLog (@ "%@", _abt.text);
}
Note: Dalloc is written in the controller that creates the viewer
-(void) dealloc
{
After the message is sent, remove
[[Nsnotificationcenter defaultcenter]removeobserver:self name:@ "abc" Object:nil];
}
Summary: To sum up, the notification Center is very suitable for use when the two view controllers are associated with little, lightweight values, comparable to attribute values
Notification Pass Value