• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Autocomplete word as you are typing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Autocomplete word as you are typing (From: Chris Schmitt <email@hidden>)

  • Prev by Date: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Next by Date: Re: Determining if a url exists
  • Previous by thread: Re: Autocomplete word as you are typing
  • Next by thread: NSCollectionView questions
  • Index(es):
    • Date
    • Thread