- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self addObserver:self forKeyPath:@"buul" options: NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
}
//觀察者觀察到有值發生改變的時候發生的方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
//change 字典中的old new 是關鍵字,專門用來存儲新值和老值
NSLog(@"=====原始值=%@",[change objectForKey:@"old"]);
NSLog(@"=====新值=%@",[change objectForKey:@"new"]);
}
// 删除監聽對象
-(void)viewWillDisappear:(BOOL)animated{
[self removeObserver:self forKeyPath:@"buul" context:nil];
}