NSTokenField Suggest but don't complete
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开发者_Go百科 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?
- (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.
In swift the answer is:
if selectedIndex != nil {
selectedIndex.memory = -1
}
精彩评论