2

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.

AWF4vk
  • 5,810
  • 3
  • 37
  • 70
  • I'm retrieving via [comboBox stringValue]; – AWF4vk Jul 09 '11 at 01:14
  • @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 Jul 09 '11 at 01:15

2 Answers2

4

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

From here:

I got the selected value using:

NSString *strValue = [comboBox itemObjectValueAtIndex:[comboBox indexOfSelectedItem]];
Community
  • 1
  • 1
Chris Gregg
  • 2,376
  • 16
  • 30
  • Doesn't work. Exception thrown: `*** -[NSComboBoxCell itemObjectValueAtIndex:] should not be called when usesDataSource is set to YES` – AWF4vk Jul 09 '11 at 01:16