最簡單的方式
在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)