NSTokenField Suggest but don't complete

725 views Asked by At

I feel like this must be a common issue that I'm just struggling to figure out, but I couldn't find anyone else who asked the question so... Basically I have an NSTokenField and when the user begins typing I make a SOAP request and get names that are similar to what they have entered. The issue is my suggestions don't necessarily match what they have typed. For example, I match email and last names, but a persons full name appears in the suggestion array. Since the letters don't match, NSTokenField changes what has already been typed to the first item in the array. Is there a way to turn off autocomplete and just have the suggestion box appear?

2

There are 2 answers

0
Phil On BEST ANSWER
    - (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
{
    *selectedIndex = -1;
    return NSArray;
}

It turns out that I was assigning selectedIndex incorrectly but if you just set it to -1 then nothing is selected.

0
KVISH On

In swift the answer is:

if selectedIndex != nil {
    selectedIndex.memory = -1
}