使用 Binding 时 NSTokenField 的值到底应用在哪里?

发布于 2025-01-16 12:40:47 字数 657 浏览 6 评论 0原文

我当前正在使用 NSTokenField ,并将其值绑定到 IB 中配置的 NSArrayController keypath。这一切都很好。

现在我很难将 NSTokenField 的初始大小调整为 NSArrayController 填充的初始数据 - 我缺少一个对所设置的值做出反应的钩子。 根据Apple的绑定指南解释以 NSTextFieldNSTokenField 的基类)为例的绑定的内部工作原理应该是setObjectValue: 在某个时刻被调用以用数据填充 NSTokenField。最有趣的是,这个方法从未被调用。因此,为了找出令牌字段从数组控制器获取数据的其他位置,我尝试了以下操作:

- (void)setObjectValue:(id)objectValue {
    [super setObjectValue:objectValue];
    NSLog(@"
              

I'm currently using an NSTokenField with a binding of its value to an NSArrayController keypath configured in IB. This works all well.

Now I'm having difficulties adjusting the initial size of the NSTokenField to the initial data it's being populated with by the NSArrayController - I'm missing a hook to react to the value being set. According to Apple's Binding Guide explaining the inner workings of a binding with the example of an NSTextField (the base class for NSTokenField) it should be setObjectValue: that is invoked at some point to fill the NSTokenField with data. Most interestingly this method is never called. So to find my out where else the token field gets its data from the array controller, I tried the following:

- (void)setObjectValue:(id)objectValue {
    [super setObjectValue:objectValue];
    NSLog(@"???? setObjectValue with: %@", objectValue);
}
- (void)setValue:(id)value forKey:(NSString *)key {
    [super setValue:value forKey:key];
    NSLog(@"???? Set value %@ for key %@", value, key);
}

- (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
    [super setValue:value forKeyPath:keyPath];
    NSLog(@"???? Set value %@ for keypath %@", value, keyPath);
}

- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
    [super setValuesForKeysWithDictionary:keyedValues];
    NSLog(@"???? Set value for keys with dict %@", keyedValues);
}

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary<NSKeyValueChangeKey,id> *)change
                       context:(void *)context {
    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    NSLog(@"???? keyPath: %@ ofObject: %@ change: %@ context: %@", keyPath, object, change, context);
}

No one of these methods ever fires, at least not for any of the value key paths of the NSTokenField. So - how is the value of the token field set? At the moment to me it's pure magic and the situation leaves me clueless.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半步萧音过轻尘 2025-01-23 12:40:49

该值在 -[NSTokenFieldCell setObjectValue:] 中设置。我不知道为什么是细胞而不是对照。

The value is set in -[NSTokenFieldCell setObjectValue:]. I don't know why it's the cell instead of the control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文