0

I have populated this NSTableView using binding from an NSArrayController

https://www.dropbox.com/s/igx8ttdfvi2tt09/ss.png

Now when the user changes say 480 (in column width) to 240 i want to change the Height value also like from 270 to 185 accordingly.

What is the correct way to do this?

Can anybody help?

Thanks

Anand

1 Answers1

0

Just override the setters for each height and width and change the other's value.

In other words, if both height and width are properties of the same object, have setHeight call setWidth, etc.

The easiest way to do that would be if you have a third property that reflects the relationship you wish height and width to have, such as aspectRatio.

Alternately to overriding the setters, if you want to do the calculation based on the previous value of height or width, you could register for KVO changes in both keypaths with options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) and in observeValueForKeyPath you'd get a change dictionary with both the old and new values, from which you could calculate how much the user scaled the value and scale the other value accordingly (while careful to avoid triggering KVO when doing so). See registering for KVO observing in the KVO programming guide. But KVO is more difficult and prone to error, so I'd avoid it and maintain the consistency in your data model through overriding the setters.

stevesliva
  • 5,351
  • 1
  • 16
  • 39