Benches Uncategorized

1

NSArrayController to NSPopUpButtonCell - NSValu...

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have an NSTableView bound to an NSArrayController and everything works fine. What I would like to do is use an NSPopUpButtonCell to limit the choices people have to enter into a certain column. The columns, pretty typically, represent vales of dictionaries that are in the array and need to get the value selected in the pop-up into the dictionary and vice-versa.

I created the NSPopUpButtonCell, created an NSMenu and made the necessary attachments. The menu shows up as desired and makes changes but the selection shows for a moment and then reverts to the blank "no selection" setting. Do I need to write a value transformer to connect these two elements together or is it possible to do with the binding magic? I know that pop-ups usually actually return an NSNumber of the index of the selection and even that would work for me if I can do it simply through bindings.

Anyone done this already and care to shed some light?

Thanks,

=Tod

1 reply

Sign in or join Beachball Help to reply.

  1. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    As usual I found the answer shortly after publicly posting and asking for help.

    This documentation from Apple isn't exactly related but was helpful: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Tasks/on erelation.html

    The real trick is that you bind to the column itself and not the NSPopUpButtonCell.

    In the end the only necessary column binding is:

    selectedValue:
    *Bind to: MyArrayController*
    *Control Key:arrangedObjects*
    *Model Key Path:properties.propertyname*

    Note here that I have an NSMenu defining the choices and I am initializing propertyname on creation to match one of the NSMenu entries.

    Hopefully this will save someone else some time in the future.

    =Tod