Re: Autocomplete word as you are typing
Re: Autocomplete word as you are typing
- Subject: Re: Autocomplete word as you are typing
- From: Stéphane Sudre <email@hidden>
- Date: Wed, 6 Feb 2008 23:43:04 +0100
On Feb 6, 2008, at 10:50 PM, Chris Schmitt wrote:
I am trying to figure out how I would go about doing an
autocompletion of a word as you are typing. I am trying to do
something like any autocomplete done on the web where you start
typing in your information and if there is a 1 to 1 match against a
list it suggests a completion to the word. I know there is the
"textView:completions:forPartialWordRange:indexOfSelectedItem:"
delegate method, but I want something that will happen as the
person types without hitting the escape key.
Does anyone have any examples, advice, delegate methods to look at.
Maybe something like this (not tested, just wrote it in Mail):
[[NSNotificationCenter defaultNotificationCenter] addObserver:self
selector:@selector(controlTextDidChange:)
name: NSControlTextDidChangeNotification
object: myTextControl];
[NSNotificationCenter defaultNotificationCenter] addObserver:self
selector:@selector(controlTextDidEnd:)
name: NSControlTextDidEndEditingNotification
object: myTextControl];
...
- (void) controlTextDidChange:(NSNotification *) inNotification
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[NSObject performSelector:@selector(myCompletionRoutine:)
withObject: [[inNotification userInfo] objectForKey:@"NSFieldEditor"]
afterDelay:1.0f];
}
- (void) controlTextDidEnd:(NSNotification *) inNotification
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
- (void) myCompletionRoutine:(NSTextFieldCell *) inTextFieldCell
{
// Do your completion
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden