Two way binding when setter is overriden

Posted by Nicolas Goy on Stack Overflow See other posts from Stack Overflow or by Nicolas Goy
Published on 2012-10-25T22:57:14Z Indexed on 2012/10/25 23:00 UTC
Read the original article Hit count: 174

I have an NSTextField bound to some object "zoom" property.

In this object's class implementation, I have the following

- (void)setZoom:(CGFloat)zoom
{
    _zoom = MAX(0, MIN(10, zoom));
}

If I write "-5" in the textfield, setZoom: will be called with "-5" as argument and _zoom will be set to 0.

Then problem is that the textfield is not updating itself and it shows "-5" instead of re-reading the property value it has just set.

If I do myObject.zoom = -5; in code, the text field will display 0 correctly.

I tried to wrap _zoom =... inside willChangeValueForKey/didChangeValueForKey calls but it didn't change anything.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about properties