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: Joel Norvell <email@hidden>
- Date: Mon, 18 Feb 2008 01:52:06 -0800 (PST)
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