通知中心

最简单的方式

 

在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)

 

 

 

 

 

未完待续...

posted on 2015-08-31 17:39  🌞Bob  阅读(243)  评论(0编辑  收藏  举报

导航