• 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: How to detect focus on an NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to detect focus on an NSTextField


  • Subject: Re: How to detect focus on an NSTextField
  • From: Adam Gerson <email@hidden>
  • Date: Tue, 19 Feb 2008 03:51:46 -0500

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


  • Follow-Ups:
    • Re: How to detect focus on an NSTextField
      • From: Jon Hess <email@hidden>
References: 
 >Re: How to detect focus on an NSTextField (From: Joel Norvell <email@hidden>)

  • Prev by Date: Re: Binding to NSTextView, works on 10.5 but not 10.4
  • Next by Date: Re: How to detect focus on an NSTextField
  • Previous by thread: Re: How to detect focus on an NSTextField
  • Next by thread: Re: How to detect focus on an NSTextField
  • Index(es):
    • Date
    • Thread