How to observe NSScroller changes?

Posted by Paperflyer on Stack Overflow See other posts from Stack Overflow or by Paperflyer
Published on 2010-04-22T19:13:09Z Indexed on 2010/04/22 21:13 UTC
Read the original article Hit count: 272

Filed under:
|
|

I have an NSScrollView subclass and I would like to update another NSView based on the current scroll position. I tried KVC-observing the value of [self horizontalScroller] but that never gets called.

// In awakeFromNib
[[self horizontalScroller] addObserver:self
                            forKeyPath:@"value"
                               options:NSKeyValueObservingOptionNew
                               context:NULL];

// Later in the file
- (void)observeValueForKeyPath:(NSString *)keyPath 
                  ofObject:(id)object 
                    change:(NSDictionary *)change 
                   context:(void *)context {
    if (object == [self horizontalScroller] && [keyPath isEqualToString:@"value"]) {
        // This never gets called
    }
}

Do you see an error in my reasoning or know a better method of how to observe the scrolling of an NSScrollview?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about kvc