通知中心注册通知,发送通知
1.A类注册一个通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(jump) name:@"jump" object:nil];
-(void)jump{
NSLog(@"A类中的通知");
}
2.B类注册一个通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(jump) name:@"jump" object:nil];
-(void)jump{
NSLog(@"B类中的通知");
}
3. //发送通知
[[NSNotificationCenter defaultCenter]postNotificationName:@"jump" object:nil];
[self dismissViewControllerAnimated:YES completion:nil];
4.打印结果:A类中的通知
B类中的通知
说明注册过该通知的每一个类都会收到通知
初探佳境,多多学习交流