【发布时间】:2011-11-03 20:53:14
【问题描述】:
在我的一生中,我无法让 KVO 与 UISwitch 一起工作。我有一个自定义 UITableViewCell ,其中包含通过 Interface Builder 添加的 UISwitch 。我为 UISwitch 创建了一个 IBOutlet 并将其链接到 theSwitch 变量。
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[theSwitch addObserver:self forKeyPath:@"on" options:NSKeyValueObservingOptionNew context:NULL];
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSLog(@"toggled switch");
}
observeValueForKeyPath:ofObject:change:context 永远不会被调用!
【问题讨论】:
标签: ios key-value-observing uiswitch