Re: Finding which control is selected
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