通知

1.通知中心添加监听器

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)aName object:(id)anObject;

对象(observer)监听对象(anObject)发送的什么(aName)通知,去执行什么(SEL)

2.通知中心发布通知

- (void)postNotificationName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo;
对象(anObject)发送什么(aName)类型的通知,有什么信息(aUserInfo)

监听对象要想监听通知对象发布的特定类型的信息,通知名称必须一致

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //移除通知中心的观察者,移除所有观察者
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    //移除某个观察者
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"123" object:nil]; 
}
原文地址:https://www.cnblogs.com/bachl/p/4680842.html