NSWindowController does not implement commitEditing, though.

NSViewController does but I have to use NSWindowController since my
dialog is a modal window (sheet).

Can I have my cake and eat it too?

On Mon, Jan 7, 2013 at 9:40 PM, jonat...@mugginsoft.com
<jonat...@mugginsoft.com> wrote:
>
> On 2 Jan 2013, at 21:03, Joel Reymont <joe...@gmail.com> wrote:
>
>> I have a dialog (sheet) with a single text field and a button.
>>
>> I'm using Cocoa Bindings to validate the value in the text field and
>> set a string field in the File's Owner.
>>
>> This works fine but I would like to trigger the same sequence of
>> events when pressing the button. How do I do this?
>
> Try calling -commitEditing on your object controller.
>
> I also on occasion make use of the following NSWindow category method.
> Most controls perform validation etc when they loose first responder status.
> This method causes validation to occur by temporarily making the window its 
> own responder.
>
> /*
>
>  end all editing in window
>
>  */
> - (BOOL)endEditing:(BOOL)force
> {
>         id firstResponder = [self firstResponder];
>
>         // gracefully end all editing in a window named aWindow
>         if ([self makeFirstResponder:self])  {
>                 // All editing is now ended and delegate messages sent etc.
>         } else if (force) {
>                 // For some reason the text object being edited will not 
> resign
>                 // first responder status so force an end to editing anyway.
>         // This is probably a bad idea as the first responder is probably 
> refusing to resign
>         // its status because of a pending or failed validation.
>         // forcing the edit can leave our model in an invalid state.
>                 [self endEditingFor:nil];
>         } else {
>         return NO;
>     }
>
>         // restore the first responder once editing completed.
>         // this is required in situations where this message is sent from
>         // - (void)windowDidResignKey:(NSNotification *)notification.
>         // a panel, such as the find panel, may be being displayed.
>         // it will require the window's firstResponder to be maintained.
>         [self makeFirstResponder:firstResponder];
>
>     return YES;
> }
>
>
> Regards
>
> Jonathan Mitchell
> Mugginsoft LLP
>
>
> _______________________________________________
>
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/joelr1%40gmail.com
>
> This email sent to joe...@gmail.com



-- 
--------------------------------------------------------------------------
for hire: mac osx device driver ninja. kernel, usb and coreaudio drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to