我正在練習與關鍵值觀察,但這是我不明白的東西。一些幫助關鍵值觀察與滑塊
我有一個滑塊(sldMoving),當它移動時,假設控制檯顯示「已經改變」。雖然還有其他方法可以做到,但我很好學習。
在 - (無效)viewDidLoad中執行得好:
[super viewDidLoad];
[self.sldMoving addObserver:self forKeyPath:@"self.sldMoving.value" options:NSKeyValueObservingOptionNew context:NULL];
,並在observaValueKeyPath:
-(Void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context {
if ([keyPath isEqualToString:@"self.sldMoving.value"]) {
NSLog(@"I Have change");
顯然,這廢話我寫了不起作用。
錯誤:
2012-08-25 20:17:07.611 Example[3947:c07] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ addObserver: forKeyPath:@"sldMoving.value" options:0x101 context:0x0] was sent to an object that is not KVC-compliant for the "sldMoving" property.' * First throw call stack: (0x136b022 0x1060cd6 0x1313a48 0x13139b9 0xadc84f 0xadeb0c 0xaddd3f 0xadc6fd 0x27ff 0x28aa1e 0x1e9401 0x1e9670 0x1e9836 0x1f072a 0x1c1596 0x1c2274 0x1d1183 0x1d1c38 0x1c5634 0x2177ef5 0x133f195 0x12a3ff2 0x12a28da 0x12a1d84 0x12a1c9b 0x1c1c65 0x1c3626 0x1efd 0x1e65) terminate called throwing an exception
我該如何解決這個問題?
謝謝。
(請原諒我的英語不好)
謝謝你的解釋。這項工作! – ivamago