English 中文(简体)
NNSCombox s 组合框BoxSelesteabe 更改后值被延迟
原标题:NSCombox s comboBoxSelectionDidChange value is delayed

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:我已经尝试过其他 NSComboBoxDelegate 方法,但发生的情况与上述我所描述的相同。

最佳回答

更改代码以使用对象ValueofSectiveTround 而不是字符串Value 。

- (void)comboBoxSelectionDidChange:(NSNotification *)notification{
    int x = [[notification.object objectValueOfSelectedItem] intValue];
    NSLog(@"ComboBox Value Changed to --> %i", x);
}
问题回答

暂无回答




相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签