Selected value of a NSPopUpButton

Hi all,

I’d like to get the current value of a popup menu when it is released, but ik keeps returning the previous selected value.

I have a NSPopUpButton in a NSView, it’s ˜Content Values’ and ˜Selected Value’ are properly binded to properties in the appDelegate script.
I have second script instance delegated to the popup to control it’s actions:


script popUpDelegate

    property parent : class "NSPopUpButton"
    property appDelegate : missing value

    on menuDidClose_(sender)
        log appDelegate's valVWvers as text
        ” the rest of the script that needs to be triggered by the release of the popup
    end menuDidClose_

end script

It all works well, except for when I release the popup, it log’s the previous selected value instead of the new one, which I need in the remaining actions it triggers.

If I use a Combo Box and a on comboBoxSelectionDidChange_(sender) handler, it returns the correct value. Needless to say, for now that’s not what I want for my user interface.

Does anybody know how to get the current selected value from a popup on the moment of release of the button?

thanks,
Cliff

Hi,

the easiest way is to use a handler like this and connect it to the selector of the popup button.


    on didSelectItem:sender
        log sender's titleOfSelectedItem() as text
    end didSelectItem

No subclassing, no bindings needed

Thanks Stefan, that’s indeed what I was looking for!

regards,
Cliff