Search code examples
objective-cmacoscocoa-bindings

NSComboBox: How to tell user has typed in information that is not in the pop up list and read it


I have an NSComboBox with a seperate class that conforms to NSComboBox dataSource and delegate.

If the user types text into the combo box that that does not match one of the items in the pop up list, how do I receieve a notification that the user has typed something in and also read the value that the user has typed?

At the moment I'm implimenting the delegate methods:-

-(void)comboBoxSelectionDidChange:(NSNotification *)notification 
-(void)comboBoxWillDismiss:(NSNotification *)notification 

However these appear only to be notified when the user has selected an item from the popup, not when the user types something else in stops editing


Solution

  • Since NSComboBox is a subclass of NSTextField, and thus NSControl, you can also use the NSControlTextEditingDelegate methods such as control:textShouldEndEditing: to affect the behavior of your combo box.