Re: NSTextField and key-events
Re: NSTextField and key-events
- Subject: Re: NSTextField and key-events
- From: Matt Gemmell <email@hidden>
- Date: Sat, 21 Jun 2003 17:12:36 +0100
On 21/6/03 at 4:56 pm, Patrick Gundlach said:
>
I'd like to create an interface with IB. My goal is to get an
>
NSTextField-alike field, where I get the keys the user types in before
>
he/she presses enter but with visual feedback. So something like the
>
search field in iTunes or Address Book. These applications act before
>
the user presses the enter key on the keyboard.
Hi Patrick,
You don't need to create any subclasses of NSTextField to do this; it's
actually a lot easier than you think. All you need to do is create an
object to be the "delegate" of your NSTextField. You can set your
NSTextField's delegate in Interface Builder, if you like.
In the delegate object, just implement this method:
- (void)controlTextDidChange:(NSNotification *)aNotification;
That method will automatically be called whenever the text in your
NSTextField changes in any way (it will be called once for each change,
including any keypresses, deletion, pasting, and so on). You can then
access the current text by calling -[NSTextField stringValue], and do
whatever you need to with it.
Cheers,
-Matt
--
Matt Gemmell
Scotland Software
http://www.scotlandsoftware.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.