2
votes

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.

2
I'm retrieving via [comboBox stringValue];AWF4vk
@Bavarious: objectValueOfSelectedItem won't work since I'm using a dataSource. Exception thrown: ` *** -[NSComboBoxCell objectValueOfSelectedItem] should not be called when usesDataSource is set to YES `AWF4vk

2 Answers

4
votes

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.

2
votes

From here:

I got the selected value using:

NSString *strValue = [comboBox itemObjectValueAtIndex:[comboBox indexOfSelectedItem]];