【问题标题】:Bindings does not update NSTextField绑定不更新 NSTextField
【发布时间】:2017-02-13 14:14:52
【问题描述】:

我在 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];
}

【问题讨论】:

    标签: objective-c cocoa cocoa-bindings kvc


    【解决方案1】:

    我忘记了我使用具有最小值/最大值的 NSNumberFormatter 来阻止 NSTextField 更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2012-05-23
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      相关资源
      最近更新 更多