lundi 13 février 2017

Bindings does not update NSTextField

Vote count: 0

I use bindings to NSObjectController within XIB. When I set new content object of NSObjectController the only value which doesn't change is the one that has first responder. If I don't use custom getter/setter even the textfield that has firstResponder (isBeingEdited) changes.

What's wrong with my KVC, KVO?

My custom getter/setter is below pic. PS: I don't want to make window a first responder before I change content object to make it work.

enter image description here

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

asked 44 secs ago

Let's block ads! (Why?)



Bindings does not update NSTextField

Aucun commentaire:

Enregistrer un commentaire