• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextField value binding and button click
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField value binding and button click


  • Subject: Re: NSTextField value binding and button click
  • From: Lieven Dekeyser <email@hidden>
  • Date: Tue, 29 Jan 2008 11:56:31 +0100

On 28 Jan 2008, at 23:35, Quincey Morris wrote:

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.


Unfortunately, it doesn't seem to be working as advertised. When I use an NSObjectController, I still have to call -commitEditing on it when the button is clicked, otherwise my model is not updated... I'd expect NSTextField to lose focus and commit automatically when the user clicks a button, but the field doesn't seem to lose focus...

--Lieven_______________________________________________

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


  • Follow-Ups:
    • Re: NSTextField value binding and button click
      • From: Quincey Morris <email@hidden>
    • Re: NSTextField value binding and button click
      • From: "Kyle Sluder" <email@hidden>
References: 
 >NSTextField value binding and button click (From: "Lieven Dekeyser" <email@hidden>)
 >Re: NSTextField value binding and button click (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Pushing the truth
  • Next by Date: Re: CoreData - multiple stores advice...
  • Previous by thread: Re: NSTextField value binding and button click
  • Next by thread: Re: NSTextField value binding and button click
  • Index(es):
    • Date
    • Thread