通知中心注册通知,发送通知

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类中的通知

   说明注册过该通知的每一个类都会收到通知       

posted @ 2016-05-20 15:03  有棱角的圆  阅读(179)  评论(0编辑  收藏  举报