通知的初级使用

A视图是B视图的父,B向A传质,第一步要在B中注册通知中心:

-(void)buttonClikc
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"changeColor" object:@"heeo"];
    [self.navigationController popToRootViewControllerAnimated:YES];
}


第二步,在A中添加观察者

 self.view.backgroundColor = [UIColor cyanColor];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeBackGroundColor:) name:@"changeColor" object:nil];
    //接收消息以后就会触发某方法,这个方法必须带有参数,参数的数据类型是固定 的,NSNotification
}
-(void)changeBackGroundColor:(NSNotification *)notification
{
    //消息携带的内容
    UIColor * color = notification.object;
    self.view.backgroundColor = color;
}

OK了,可以进行反向传质。

 
原文地址:https://www.cnblogs.com/huoxingdeguoguo/p/4598469.html