使用Cocoa Bindings传播编程式文本字段值更改为模型 [英] Propagate programmatic text field value changes to model using Cocoa Bindings
问题描述
我尝试了一个非常简单的实现,像这样:
I tried a very simple implementation, like this:
@implementation ScrollingTextField
- (void)scrollWheel:(NSEvent *)event {
self.doubleValue -= event.scrollingDeltaY;
}
@end
我绑定了
滚动文本字段到某个其他对象。滚动现在更新文本字段上的可见文本很好。但是,绑定值不会改变。
I bound the value
of the scrolling text field to some other object. Scrolling now updates the visible text on the text field just fine. However, the bound value does not change.
为什么绑定值不变?
或者:如何使绑定值识别变化?
Why does the bound value not change? Or: How can I make the bound value recognize the change?
推荐答案
绑定值不会更改< a href =https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Concepts/Troubleshooting.html#//apple_ref/doc/uid/TP40002148-182809>由Apple的设计。要在更改后自己将值传播给模型,请修改此代码:
The bound value doesn't change by Apple's design. To propagate the value to the model yourself after a change, adapt this code:
NSDictionary *bindingInfo = [self infoForBinding:NSValueBinding];
[[bindingInfo valueForKey:NSObservedObjectKey] setValue:self.doubleValue
forKeyPath:[bindingInfo valueForKey:NSObservedKeyPathKey]];
(感谢@DrummerB的苹果链接!)
(Thanks @DrummerB for that Apple link!)
这篇关于使用Cocoa Bindings传播编程式文本字段值更改为模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!