• 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: Force bindings to sync
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Force bindings to sync


  • Subject: Re: Force bindings to sync
  • From: "email@hidden" <email@hidden>
  • Date: Wed, 25 Mar 2009 21:22:13 +0000


On 25 Mar 2009, at 21:07, Sidney San Martín wrote:

I'm trying out Cocoa bindings in my application, mostly on NSTextFields, and am running into a small glitch.

While my object is updated just fine when a field loses focus, nothing happens when the window is closed or a button is clicked: the last-edited field is always out of sync. How can I force the focused element to "commit" its changes?

You you should read up on the NSEditor and NSEditorRegistration Protocols as implemented by NSController and its subclasses.


Your binding is not being updated because controls tend to commit their data when they resign as first responder.
NSButton doesn't accept first responder status hence when you click to say close a window your binding remains cold.


The trick is to use an NSController subclass for all your bindings and call - (BOOL)commitEditing whenever committal is required.

If you have neglected to use an NSController you can ask the window itself to end editing.
Add the following to an NSWindow category and give it a whirl.


/*

 end all editing in window

 */
-(void)endEditing
{

	// gracefully end all editing in a window named aWindow
	if([self makeFirstResponder:self])
	{
		// All editing is now ended and delegate messages sent etc.
	}
	else
	{
		// For some reason the text object being edited will not resign
		// first responder status so force an end to editing anyway
		[self endEditingFor:nil];
	}
}



_______________________________________________

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

Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




_______________________________________________

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


References: 
 >Force bindings to sync (From: Sidney San Martín <email@hidden>)

  • Prev by Date: Re: Force bindings to sync
  • Next by Date: Re: Force bindings to sync
  • Previous by thread: Re: Force bindings to sync
  • Next by thread: Safari 4-like popup menu
  • Index(es):
    • Date
    • Thread