Re: Newbie - which NSTextField is the cursor in?
Re: Newbie - which NSTextField is the cursor in?
- Subject: Re: Newbie - which NSTextField is the cursor in?
- From: email@hidden
- Date: Sun, 17 Mar 2002 23:31:42 -0800
I have an fairly straightforward MVC-type app with several NSTextFields,
one of which (we'll call it T) I'm toggling between
editable/non-editable states depending on the state of a check box. If
the cursor is in T when the check box gets unchecked, I first make T
uneditable and then I want to politely put the cursor in another field
for the user, but to do this I need to be able to find out which
NSTextField the cursor is in (I don't want to touch the cursor if it is
not in T). I've tried looking at [NSView focusView] but this returns
the check box that just got clicked, and [Window firstResponder] doesn't
seem to help either. I guess I could track it myself with a global by
adding notifiers to each NSTextField, but I suspect there is an easier
way that I'm missing. Any suggestions to help me on my way?
[window firstResponder] should be correct in theory. However, I think
it might return the field editor for the textfield, not the textfield
itself. I'm not sure offhand how to get from the field editor back to
the original textfield. With that link in the chain filled in, though,
I believe this would work. Assuming you called -firstResponder *before*
dimming the textfields, of course. :->
You might try saving a reference to [window firstResponder], disabling
the textfield T, and then checking to see if [window firstResponder] has
changed. If it has, T was presumably the editing textfield, and you can
set the user's first responder accordingly.
However, may I just say that this sounds like a questionable UI to
me. I don't want to be put into a textfield as first responder unless
the HI guidelines say I should be, personally...
[NSView focusView] is a pretty specialized thing; until you've got
enough Cocoa experience to *know* that it's what you want, it's pretty
much guaranteed to not be what you want. :->
Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.