Re: Overriding NSTextField keyDown?
Re: Overriding NSTextField keyDown?
- Subject: Re: Overriding NSTextField keyDown?
- From: Douglas Davidson <email@hidden>
- Date: Tue, 6 Jan 2009 10:28:38 -0800
On Jan 2, 2009, at 3:45 PM, Mr. Gecko wrote:
Hello, I've been trying to override the NSTextField keyDown method,
but it didn't seem to work. I've searched in the archives, but got
nowhere, all I could find is to override the text field editor. But
how could I do that?
This is all very confusing. All I really need to do is when the user
push return (36) or enter (76) it will run a method goTo. and
eventually I'll want to do the up and down arrows.
You really don't want to do that. What you need to do is to work with
the frameworks rather than against them, and everything will go
smoothly. NSTextFields and other controls handle all of the standard
keystrokes themselves, but of course they allow you to override their
behavior at many points. The first thing to do would be to try some
of the tutorials that handle text fields, in particular using IB to
set up the target-action mechanism.
If that doesn't quite suit your needs, but what you're interested in
is learning when a particular field has ended editing, there's a
standard notification you can listen for. If you want to customize a
text field and give special handling to certain special keys, there's
a delegate method -control:textView:doCommandBySelector:.
What you definitely don't want to do is override keyDown:. In the
first place, it isn't the text field that gets the keyDown:, but the
field editor; but even if you had a custom field editor, you wouldn't
want to override keyDown:, because doing so will break most input
methods. Dealing with raw key strokes is too crude for the needs of
modern text input--that's why we have all of these other override
points. Check the archives for my earlier messages on this topic.
Douglas Davidson
_______________________________________________
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