I have a NSAlert with a combobox in it and i need to know it’s value every time it changes.
In my .h i have implemented the NSComboBoxDelegate protocol and NSComboBox* comboBox.
In my .m i have:
[comboBox setDelegate:self];
- (void)comboBoxSelectionDidChange:(NSNotification *)notification{
int x = [[comboBox stringValue] intValue];
NSLog(@"ComboBox Value Changed to --> %i", x);
}
But here is the problem:
the default value of the combobox is 2. if i change the value to, for example, 6 my NSLog displays: ComboBox Value Changed to --> 2
Then, when i change it’s value back to 2, my NSLog displays: ComboBox Value Changed to --> 6
Any ideas about this problem?
Thank you.
PS: i have tried other NSComboBoxDelegate methods but it happens the same thing as i described above.
Change the code to use objectValueOfSelectedItem instead of stringValue.