////VIEWCONTROLLER.M//notification mechanism////Created by Mac on 16/1/2.//copyright©2016 year Mac. All rights reserved.//#import "ViewController.h"#import "CZPerson.h"#import "CZGroup.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Czperson*p1=[[Czperson alloc]init]; P1.name=@"Z"; Czperson*P2 =[[Czperson alloc]init]; P2.name=@"h"; Czgroup*G1 =[[Czgroup alloc] init]; G1.name=@"G1"; Czgroup*G2 =[[Czgroup alloc]init]; G2.name=@"G2";//Notification CenterNsnotificationcenter *center =[Nsnotificationcenter Defaultcenter];//Initialize a notificationNsnotification *n1 = [nsnotification notificationwithname:@"Nongniunai" Object: G1 userinfo:@{@"Count":@2,@"TX":@"haha"}]; //Subscribe to Notifications[Center ADDOBSERVER:P1 selector: @selector (Shouniunai:) Name:@"Nongniunai" Object: G1];//Send a notification[center postnotification:n1]; //Publish Notifications }@end
2016-1-2 Learning of notification Mechanism 2: Code implementation