Does anyone know of any class or lib that can implement autocomplete for NSTextField?
I am trying to make standard autocomplete work, but it is made as a synchronous api. I get my autocomplete words through an api call over the Internet.
What i have done so far:
- (void)controlTextDidChange:(NSNotification *)obj { if([obj object] == self.searchField) { [self.spinner startAnimation:nil]; [self.wordcompletionStore completeString:self.searchField.stringValue]; if(self.doingAutocomplete) return; else { self.doingAutocomplete = YES; [[[obj userInfo] objectForKey:@"NSFieldEditor"] complete:nil]; } } }
When my store is completed, I have a delegate that is called:
- (void) completionStore:(WordcompletionStore *)store didFinishWithWords:(NSArray *)arrayOfWords { [self.spinner stopAnimation:nil]; self.completions = arrayOfWords; self.doingAutocomplete = NO; }
Code that returns a list of completions in the nstext field:
- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index { *index = -1; return self.completions; }
My problem is that it will always be 1 request behind, and a completion list is only shown on every second char user input.
I tried to find google and SO as a crazy person, but I can not find any solutions.
Any help is greatly appreciated.
objective-c autocomplete cocoa nstextfield
Rasmus styrk
source share