Search code examples
macosnotificationsnscombobox

comboBoxSelectionDidChange gives me previously selected value


I am using this notification for NSComboBox. Only problem is when I select a different item in the dropdown it always show previously selected value in the combo box. How can I get the currently selected value. I need to make some controls enable/disable based on the value.

- (void)comboBoxSelectionDidChange:(NSNotification *)notification {
        NSComboBox *comboBox = (NSComboBox *)[notification object];

        NSLog(@"[comboBox stringValue] : %@", [salaryBy stringValue] );
}

Solution

  • I got the selected value using:

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