相关疑难解决方法(0)

KVO不与UISwitch合作

对于我的生活,我无法让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");
}
Run Code Online (Sandbox Code Playgroud)

observeValueForKeyPath:ofObject:change:从不调用context!

key-value-observing uiswitch ios

4
推荐指数
1
解决办法
1937
查看次数

标签 统计

ios ×1

key-value-observing ×1

uiswitch ×1