![](/img/trans.png)
[英]With Cocoa Bindings, changing the value of NSTextField programmatically does not update the model
[英]Bindings does not update NSTextField
我在XIB中使用對NSObjectController的綁定。 當我設置NSObjectController的新內容對象時,唯一不變的文本字段值是具有第一響應者的值。 模型更改沒有問題。
如果我不使用自定義getter / setter,則具有firstResponder(isBeingEdited)的文本字段會毫無問題地進行更改。
我的KVC,KVO怎么了?
我的自定義getter / setter在圖片下方。 PS:在更改內容對象以使其正常工作之前,我不想讓窗口成為第一響應者。
static const CGFloat MMsInOneInch = 25.4;
static const CGFloat inchesInOneMM = 0.0393700787402;
- (void)setPaperWidth:(CGFloat)paperWidth
{
[self willChange];
CGFloat newWidth = paperWidth * [self conversionKoeficientToDefaultUnitType];
if (!_isChangingPaperSize) {
if (self.paperSize == PPPaperSizeA4 && fabs(newWidth - widthSizeOfA4) > 0.001) {
[self setPaperSize:PPPaperSizeCustom];
}
if (self.paperSize == PPPaperSizeUSLetter && fabs(newWidth - widthSizeOfUSLetter) > 0.001 ) {
[self setPaperSize:PPPaperSizeCustom];
}
}
[self willChangeValueForKey:@"paperWidth"];
_paperWidth = newWidth;
[self didChangeValueForKey:@"paperWidth"];
[self didChange];
}
- (CGFloat)conversionKoeficientToDefaultUnitType
{
if ([self defaultUnitType] == [self unitType]) {
return 1;
}
if ([self defaultUnitType] == PPPrintSettingsUnitTypeMM) {
return MMsInOneInch;
}
if ([self defaultUnitType] == PPPrintSettingsUnitTypeInch) {
return inchesInOneMM;
}
return 1;
}
- (CGFloat)paperWidth
{
return _paperWidth / [self conversionKoeficientToDefaultUnitType];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.