- (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];
}