0

I have a combo box with a array of items in string. After i click the arrow to show all the items, i want when i press a key which represent first letter of a item then the respective item will be selected (item is highlighted and NSComboBoxSelectionDidChangeNotification is posted). TextField of combobox is set to not be editable in this case.

I'm new to cocoa and objective and I don't know how to implement this. I try to implement all methods of NSComboBoxDataSource protocol but the item is highlighted without any notification when i input text to textfield of combobox which is then editable (just a try because i want it isn't editable).

Any suggestion would be appreciated.

Huy Ha
  • 120
  • 10
  • Is the text field never editable? How about a popup button? – Willeke Feb 01 '19 at 10:53
  • @Willeke Textfield isn't editable. You can only select an item from combobox. I don't understand what you want to ask about popup button. When we click it, all the items will be shown right? – Huy Ha Feb 01 '19 at 11:03
  • An uneditable combox is a pull-down button. A combobox should be editable and the contents can be autocompleted and validated. What is the number of items in the array? – Willeke Feb 01 '19 at 13:27
  • @Willeke I tried on using editable combo box. The inputed text is autocompleted as you said. The problem is itemselectiondidchange event isn't triggered even though i press enter. I need to catch this event to update UI. Selection through mouse click is fine. Number of item in the array is set by overriden method of nscomboboxdatasource protocol. – Huy Ha Feb 02 '19 at 16:47
  • Is the action method called? – Willeke Feb 03 '19 at 03:10
  • @Willeke I didn't use action method. What should i do in action method? – Huy Ha Feb 11 '19 at 07:53
  • Update the UI. The action method is called when you select an item and when you press enter. – Willeke Feb 11 '19 at 09:55
  • @Willeke My targets are: - When i press a key representing first character of an item, that item is selected. - Update UI when i select an item. Action method is triggered when i click an item or i press enter no matter what inputted text is. So i can't achieve first target and have to validate inputed text. I wonder when to use comboBoxSelectionDidChange in NSComboboxDelegate protocol. Currently, I override this method to update UI (mouse click trigger this method, pressing enter doesn't). If you have time, some lines of code will help me understand your idea better. – Huy Ha Feb 12 '19 at 07:46
  • Maybe this helps: [NSComboBox: How to tell user has typed in information that is not in the pop up list and read it](https://stackoverflow.com/questions/6235122/nscombobox-how-to-tell-user-has-typed-in-information-that-is-not-in-the-pop-up). – Willeke Feb 14 '19 at 15:17
  • @Willeke Thanks. This link help me a lot. – Huy Ha Feb 19 '19 at 15:31

0 Answers0