I have an NSTextField associated with my model. If I programmatically change the contents of a text field, the model is not updated. I know you should update the model instead .
But I'm trying to implement a subclass of NSTextField that recognizes scrolling when the mouse hovers over it to change its numerical value. Obviously, I do not have access to the model from this subclass. So you have suggestions, how can I do this?
SOLUTION (thanks noa):
- (void)scrollWheel:(NSEvent *)theEvent {
[self setFloatValue:[self floatValue] - [theEvent deltaY]];
NSDictionary *bindingInfo = [self infoForBinding: NSValueBinding];
NSObject *boundObject = [bindingInfo valueForKey:NSObservedObjectKey];
NSString *keyPath = [bindingInfo valueForKey:NSObservedKeyPathKey];
[boundObject setValue:[NSNumber numberWithFloat:[self floatValue]]
forKeyPath:keyPath];
}
source
share