autocompletion of NSTextField

Discussion in 'Mac Programming' started by hrishidev, Apr 10, 2008.

  1. macrumors regular

    Dec 3, 2007
    I want to autocompletion of NstextField from dropdown list ...... just like the Apple Mail "new Message" does by suggesting the email ids
  2. macrumors regular

    Feb 27, 2006
    Kent, United Kingdom
    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.
  3. thread starter macrumors regular

    Dec 3, 2007
    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 :)
  4. Moderator emeritus


    Jul 24, 2002
    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 under Text Completion.

Share This Page