I have a panel with a bunch of text fields (names and scores in a high
scores list). If the user gets a high score, I make its corresponding
player name textfield selectable, editable, bezeled, and finally call
selectText on it. Seems to work. These settings seem to be persistant
after the panel closes (if the high scores panel is produced a second
time, after closing it the first time, the textfield the user originally
typed his name into is still editable.
So, to fix that, each time I produce the panel, I set selectable false
(which automatically sets editable false) and I set bezeled false for all
text fields that aren't the user's typing name.
Sometimes, though, I don't want any text field to be editable, such as
when the user is only viewing the panel, but not after a game just ended.
I can't figure out how to unselect the textfield that was selected the
previous time the panel was opened. Normally, I do this by selecting the
field the user is presently editing, this automatically unselects the
previous editing field, but I can't do that if I don't want any field to
be selected.
As a result, the text field is still not selectable, editable, or bezeled,
but it is selected. I can't type of course. If I TAB, the field becomes
unselected, but it starts out selected.
How do I fix this? NSTextField doesn't seem to have an obvious function
for this. Neither does NSControl. Am I just missing something obvious.?
Thanks.
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________
Chris Hanson - 14 Aug 2005 07:33 GMT
> As a result, the text field is still not selectable, editable, or
> bezeled, but it is selected. I can't type of course. If I TAB, the
[quoted text clipped - 3 lines]
> function for this. Neither does NSControl. Am I just missing
> something obvious.?
It's not all that obvious if you're coming from another platform or
framework. What you're looking to do is change the "first responder."
To do this, you use the method -[NSWindow makeFirstResponder:].
Since you're also trying to end editing of a text field (which uses the
"field editor," a shared object that manages input for text fields),
you'll likely want to use a combination of -[NSWindow
makeFirstResponder:] and -[NSWindow endEditingFor:] when the user
clicks the OK button in your panel. Check out the documentation for
the method -[NSWindow endEditingFor:] for the details[1], and a sample
of the kind of code you should probably have in the code that handles
your OK button press.
-- Chris
[1]
<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_cla
ssic/Classes/NSWindow.html#//apple_ref/occ/instm/NSWindow/endEditingFor:>