通知中心

最简单的方式

在b文件中建立接收者

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action) name:@"xxx" object:nil];

并在action中做出响应

在a文件中发送通知

[[NSNotificationCenter defaultCenter] postNotificationName:@"xxx" object:nil];

要先建立接收者才可以 收到通知的

记得在  addObserver: 的类文件中写上

- (void)dealloc{

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"xxx" object:nil];

}

这样写有利于性能优化,不写也可以,但是最好写上(说得就是arc)

未完待续...

原文地址:https://www.cnblogs.com/isItOk/p/4773634.html