Re: Force bindings to sync
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 (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