Search code examples
objective-ccocoanscombobox

NSComboBoxDelegate called but old 'stringValue' remains


I select a value from the drop-down of a combo box. The NSComboBox delegate fires a comboBoxSelectionDidChange: notification, but when I retrieve the stringValue of the combo box, it's the old selected value. How do I get the updated value?

I have a dataSource specified, so itemObjectValueAtIndex: and objectValueOfSelectedItem don't work.


Solution

  • If you’re using a data source, then:

    NSString *s = [yourDataSource comboBox:comboBox
                 objectValueForItemAtIndex:[comboBox indexOfSelectedItem]];
    

    should work if your data source provides strings. Otherwise, convert the object returned by this method to a string.