我目前正在使用將NSTokenField其值系結到NSArrayControllerIB 中配置的鍵路徑。這一切都很好。
現在我很難將 NSTokenField 的初始大小調整為由 NSArrayController 填充的初始資料 - 我缺少一個掛鉤來對設定的值做出反應。根據 Apple 的 Binding GuideNSTextField ,以 an (的基類)的示例解釋系結的內部作業原理,NSTokenField應該setObjectValue:在某個時候呼叫它來填充NSTokenField資料。最有趣的是,這個方法永遠不會被呼叫。因此,為了找出令牌欄位從陣列控制器獲取資料的其他地方,我嘗試了以下操作:
- (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);
}
這些方法中沒有一個會觸發,至少不會觸發valueNSTokenField 的任何關鍵路徑。那么——token欄位的值是怎么設定的呢?目前對我來說,這是純粹的魔法,這種情況讓我一無所知。
uj5u.com熱心網友回復:
該值設定在 中-[NSTokenFieldCell setObjectValue:]。我不知道為什么它是單元格而不是控制元件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/447294.html
標籤:目标-c 可可 应用套件 nstextfield 恩斯托肯菲尔德
