Re: Force bindings to sync
Thanks for the quick responses, Kyle and Jim. I really dove into bindings, so I wasn't sure where to turn in the docs, but -commitEditing does just the trick. Jonathan, thank you for the information and sample code. I'll read up. -Sidney On Mar 25, 2009, at 5:18 PM, Kyle Sluder wrote: On Wed, Mar 25, 2009 at 5:07 PM, Sidney San Martín wrote: 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? Send -commitEditing. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Force bindings to sync
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/jonathan%40mugginsoft.com This email sent to jonat...@mugginsoft.com Jonathan Mitchell Central Conscious Unit http://www.mugginsoft.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Force bindings to sync
On Mar 25, 2009, at 5:07 PM, Sidney San Martín wrote: 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? Send -commitEditing to your controller object(s). Jim ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Force bindings to sync
On Wed, Mar 25, 2009 at 5:07 PM, Sidney San Martín wrote: > 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? Send -commitEditing. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com