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.
The value is set in -[NSTokenFieldCell setObjectValue:]
. I don't know why it's the cell instead of the control.