Binding an NSPopUpButton

280 Views Asked by At

OK, so here's my situation :

  • I've got an NSDictionary, let's call it : myItem.
  • myItem.valueNames contains the values that I want to show up in the popup
  • myItem.values contains the values the popup must return (e.g. for valueName[0] -> value[0], and so on)
  • myItem.value contains the current value

How am I suppose to bind that? Even though I've studied the official reference, it still looks a bit obscure...

I'm currently binding :

  • myItem.valueNames to Content
  • myItem.values to Content Objects
  • myItem.value to Selected Value

and... all I've managed is that it shows the valueNames.

Any ideas?

1

There are 1 best solutions below

0
On

Your model is a little strange to me. I wouldn't use an NSDictionary, I'd use a custom subclass with KVC/KVO compliant properties for each of these. Also, if the name of each value is a property of the value object itself, there's no need for a separate valueNames property. So, with that change, I'd do this:

  • Bind Content to modelObject with a key path of values
  • Bind Content Values to modelObject with a key path of values.name
  • Bind Selected Object to modelObject (or yourControllerObject if that makes more sense) with a key path of value (I'd name it selectedValue)