- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
[self.txtCarPrice addObserver:selfforKeyPath:@"text"options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOldcontext:NULL]; //设置self.txtCarPrice 属性为观察者//forKeyPath:@"text"是“self.txtCarPrice”对象的属性,并非标记,注意!
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPathisEqualToString:@"text"])
{
//此时已经检测到self.txtCarPrice的值发生了变化,在此添加要响应的动作
}
}