• 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: 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

  • Follow-Ups:
    • Re: How to detect focus on an NSTextField
      • From: Adam Gerson <email@hidden>
  • Prev by Date: Re: Loading saved file into NSArrayController
  • Next by Date: Re: Loading saved file into NSArrayController
  • 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