【发布时间】:2014-02-17 04:58:48
【问题描述】:
这是我的NSArray
carType (
{
isSelected = 0;
kFieldName = "All types";
kObjectValue = 0;
kObjectValueText = All;
},
{
isSelected = 0;
kFieldName = "4 seats";
kObjectValue = 4;
kObjectValueText = "4 seats";
},
{
isSelected = 1;
kFieldName = "7 seats";
kObjectValue = 7;
kObjectValueText = "7 seats";
}
)
如何观察isSelected 字段的变化?
我在代码中使用了 KVO,但它不起作用。
carType 是context 的NSArray 属性
- (void)viewDidLoad
{
[super viewDidLoad];
[context addObserver:self forKeyPath:@"carType" options:NSKeyValueObservingOptionNew context:NULL];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"carType"]) {
NSLog(@"carType changed");
}
}
//dealloc remove observer
【问题讨论】:
标签: ios objective-c nsarray nsdictionary key-value-observing