Re: NSTextField value binding and button click
Re: NSTextField value binding and button click
- Subject: Re: NSTextField value binding and button click
- From: Quincey Morris <email@hidden>
- Date: Mon, 28 Jan 2008 14:35:52 -0800
On Jan 28, 2008, at 13:11, Lieven Dekeyser wrote:
In my app, I have a basic login form: username field, password field
and login button. The username and password fields' values are bound
to a custom controller that saves the values after editing. When the
login button is clicked, the username and password are fetched from
the custom controller.
...
Is there any way to make sure the password field's editor ends when
the user clicks on a button?
Assuming you mean "custom controller" in the MVC sense, I think all
you need to do is to insert a suitable NSController
(NSObjectController, I expect) into your NIB file and connect the text
fields to their contents through it. Here's a quote from the Cocoa
document "Cocoa Bindings Programming Topics", section "What Are Cocoa
Bindings?", subsection "Why Are NSControllers Useful?":
--
"NSController (and Application Kit user interface elements that
support binding) implements the NSEditor and NSEditorRegistration
protocols. The NSEditorRegistration protocol provides a means for an
editor (a view) to inform a controller when it has uncommitted
changes. The NSEditor protocol provides a means for requesting that
the receiver commit or discard any pending edits.
"For example, if a user is typing in a text field and then clicks a
button, the controller ensures that the model object is updated with
the complete contents of the text field before the button action takes
place.
"Although the methods are typically invoked on user interface elements
by a controller they can also be sent to a controller, for example in
response to a user’s attempt to save a document or quit an application."
--
The middle paragraph is the one that promises to do for free what you
are asking.
Alternatively, I guess you could try to make your custom controller
implement the NSEditorRegistration protocol and leave the NSController
out of the picture. I've never tried doing that, but it may be
practically trivial._______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden