I have an NSComboBox containing several items. If the user types while the list is open, I would like to select the appropriate item within the list (if there is a corresponding item).
The twist: The string in the text field is not necessarily equal to the corresponding item in the list. (The strings within the list may e.g. contain additional explanations.)
I tried implementing textDidChange:
- (void)textDidChange:(NSNotification *)notification {
NSString* nsstring = [self stringValue];
[self selectItemAtIndex: [self findCorrespondingIndex: nsstring]]; // changes text - even if documentation states that it "does not alter the contents of the combo box’s text field"
}
But, contrary to the documentation, selectItemAtIndex changes the text in the text field, so I tried the following:
- (void)textDidChange:(NSNotification *)notification {
NSString* nsstring = [self stringValue];
[self selectItemAtIndex: [self findCorrespondingIndex: nsstring]]; // changes text - even if documentation states that it "does not alter the contents of the combo box’s text field"
[self setStringValue:nsstring]; // clears selection
}
But, contrary to the documentation, setStringValue clears the selection.
Is this behavior expected?