PDA

View Full Version : autocompletion of NSTextField




hrishidev
Apr 10, 2008, 04:23 AM
I want to autocompletion of NstextField from dropdown list ...... just like the Apple Mail "new Message" does by suggesting the email ids



stadidas
Apr 10, 2008, 05:49 AM
You will need to change you text field to an instance of NSComboBox. Then, create your NSArray (or of course mutable array) of strings, and send it to the combo box like this:


[myComboBox addItemsWithObjectValues:listOfStrings];


If you want to sort the list alphabetically, you do it like this:


[listOfStrings sortUsingSelector:@selector(caseInsensitiveCompare:)];


Obviously do that before using the addItemsWithObjects method above.
To clear the list of completions in a combo box, use this method:


[myComboBox removeAllItems];


Hope that helps.

hrishidev
Apr 10, 2008, 06:18 AM
Let me make it clear ... there is 1 nstextfiled where user will type the value ......
as soon as he starts typing , suggestions will appear in dropdowns list ... usr can select any matching suggestion or he will continue typing .. as typing continues .... drop down list will change ..... .
Same like apple Mail as i mentioned earlier ....

Anyways , Thanks for your Help :)

robbieduncan
Apr 10, 2008, 07:04 AM
Use an NSTextView instead which has lots of methods to override (or delegate methods if you don't want a custom subclass) for autocompletion. See the documentation (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html) under Text Completion.