1.注册通知
NSNotificationCenter* notification = [NSNotificationCenter defaultCenter];
[notification addObserver:self selector:@selector(change:) name:@"changeImage" object:nil];
//addObserver 这个是观察者,就是说在什么地方接收通知
//selector 这个是收到通知后,调用何种方法;
//name:这个是通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
2.处理消息
- (void) change:(NSNotification*)notification
{
id obj = [notification object];//获取到传递的对象
}
3.dealloc里注销通知
[[NSNotificationCenter defaultCenter] removeObserver:self];
4发送通知(在需要发送通知的类里)
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeImage" object:self];
//object:这个对象是自身, 你要传谁的值