Re: How to detect focus on an NSTextField
Re: How to detect focus on an NSTextField
- Subject: Re: How to detect focus on an NSTextField
- From: Jon Hess <email@hidden>
- Date: Tue, 19 Feb 2008 03:00:08 -0800
I think your looking for -[NSWindow makeFirstResponder:].
Jon Hess
On Feb 19, 2008, at 12:51 AM, Adam Gerson <email@hidden> wrote:
Thanks. Do you know of a way to programatically place the user's
cursor into a TextField (Make it have focus and ready to receive the
user's typing, make it the keyView)?
Adam
Joel Norvell wrote:
I believe this is essentially what Jens suggested earlier, but more
explicit.
My code is a bit cumbersome; it's meant to be illustrative.
I believe that your NSTextField (or NSTextField subclass) will be the
NSTextView's delegate.
(The NSTextView is the fieldEditor)
So you could just say something like this:
id theFirstResponder = [[[self yourView] window] firstResponder];
if (theFirstResponder != nil)
{
NSString * firstResponderClass = [theFirstResponder className];
if ([firstResponderClass isEqualToString:@"NSTextView"])
{
id theDelegate = [theFirstResponder delegate];
if (theDelegate != nil)
{
NSString * delegateClass = [theDelegate className];
// "yourSubclass" could just be a plain "NSTextField"
if ([delegateClass isEqualToString:@"yourSubclass"])
{
// Do your stuff here.
}
}
}
}
If you've subclassed NSTextField, click-detection/activation could
be detected
through mouseDown or perhaps more appropriately through
becomeFirstResponder or
controlTextDidBeginEditing.
HTH,
Joel
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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