Re: Getting NSTextField from NSWindow firstResponder
Re: Getting NSTextField from NSWindow firstResponder
- Subject: Re: Getting NSTextField from NSWindow firstResponder
- From: Ed Watkeys <email@hidden>
- Date: Sun, 30 Nov 2003 10:06:10 -0500
On Nov 30, 2003, at 12:14 AM, James Spencer wrote:
I suspect it is a kludge but I think the problem is that you haven't
told us enough about what you are trying to do or, even more likely, I
didn't read carefully enough when you first posted and now have
deleted out the important stuff.
[...]
Again, if you are a little more precise in what you are trying to do,
we might be able to come up with a cleaner way but I can't imagine
that you need to fiddle with the field editor.
What I'm trying to accomplish is very similar in principle to what the
"deluxe" RaiseMan program does in _Cocoa Programming in Mac OS X_:
present a list of -- in my case -- directives along with some radio
buttons and text fields that can be used to edit the properties of the
currently selected directive. My current approach to being informed of
changed text fields relies on a text field invoking its action when the
user is done editing. This does not work, because some actions that the
user performs (e.g. menu selections, hitting return to "press" the
default button) do not cause the text fields' value-changed action to
be invoked. Thus, this descent into kludges, including setting the
first responder to nil to force any text field with focus to its invoke
action
This may be an instance where writing the problem down makes the
solution obvious: don't depend on the action being invoked. This
problem is arising in my attempt to cover the approach's defects, so I
should choose an approach that doesn't have any defects.
An alternative solution, similar to the one used by the RaiseMan
application: depend on the list (NSTableView) to tell me when to grab
data from the controls i.e. on selection changed. In my file saving and
other code that needs up-to-date directive information, call the same
function that the list's selection-changed delegate method depends on,
something like finishEditingDirective:.
That way, my file saving code actually makes sense to read. Here would
be the updated pseudo-code:
/* obsolete code
r = [window getFirstResponder];
[window setFirstResponder:nil];
*/
[self finishEditingDirective: [self currentDirective]];
// The active text field ended editing, so it sent a message to its
// target (me), and I stored it away in my data model.
// Create an NSData object from my data model.
/* obsolete code
[window makeFirstResponder:r];
*/
Does this make sense? Have I stumbled upon some Cocoa pattern?
Ed
_______________________________________________
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.