NSNotificationCenter 的简单的使用

观察者: (就是一个对象)一般是 接收者这个方法的类。  当有发送 名字为@"event" 的提醒通知的时候 将会触发 这个观察者中的接收者 在 object-c 中就是方法的意。

接收者:(是一个方法 selecter):就是当观察者收到 提醒通知的时候触发的那个观察者 中的 接收者(方法)

object:anObject -- 发送者:发送 提醒通知的那个类 。 如果anObject为nil.那么notification center将所有名字为@"event"的notification转发给observer

name:@"event" --接受名字(就是一个字符串) 提醒名字 : 其实就是一个 用来标识一个提醒的  当发送者发送提醒通知的时候 用来制定发给那些 设置了该提醒通知名字的观察者 

                             --如果notificationName为nil. 那么notification center将anObject发送的所有notification转发给observer

 

简单使用:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action:) name:@"event" object:nil];
然后再发出通知:
[[NSNotificationCenter defaultCenter] postNotificationName:@"event" object:nil];

 

当观察者不是self的时候 怎么弄????:

原文地址:https://www.cnblogs.com/zander/p/2597139.html