• 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: Finding which control is selected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding which control is selected


  • Subject: Re: Finding which control is selected
  • From: Brian Webster <email@hidden>
  • Date: Thu, 18 Oct 2001 15:38:52 -0500

Probably the best way to go about this is to hook up your appropriate controller object as the delegate of both text fields and implement the controlTextDidBeginEditing: and controlTextDidEndEditing: methods. The single argument is an NSNotification, and the notification's object will be the NSTextField that has just gained or lost the focus. You can use this to keep track of which text field (if any) is being edited at any given time.

On Thursday, October 18, 2001, at 03:32 PM, Peter Sichel wrote:

Thanks of your response. Here's what I'm trying to do.

I have a window with two NSTextFields. When the user clicks
on a button in the window, I want to determine which of the
two NSTextFields has input focus.

[window firstResponder] is equal to the window itself, so doesn't help.
[window fieldEditor: forObject:] returns the field editor, but
this doesn't appear to tell me which control has input focus.

What am I missing?

- Peter

The first responder _is_ the control (or more generally, the NSView) with the input focus. If you want to see if the first responder is equal to a certain control (i.e. one of your outlets), just use ==. The only place where this doesn't work is with NSTextField. When an NSTextField is selected, the window's field editor becomes the first responder, not the text field itself.

--

--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster


  • Follow-Ups:
    • Re: Finding which control is selected
      • From: Douglas Davidson <email@hidden>
References: 
 >Re: Finding which control is selected (From: Peter Sichel <email@hidden>)

  • Prev by Date: Re: Finding which control is selected
  • Next by Date: Re: Adding some polar coordinate capabilities to NSBezierPath.
  • Previous by thread: Re: Finding which control is selected
  • Next by thread: Re: Finding which control is selected
  • Index(es):
    • Date
    • Thread