• 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: simulating <enter> in a text field by pressing a button
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simulating <enter> in a text field by pressing a button


  • Subject: Re: simulating <enter> in a text field by pressing a button
  • From: Joel Reymont <email@hidden>
  • Date: Wed, 09 Jan 2013 21:12:01 +0000

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, email@hidden
<email@hidden> wrote:
>
> On 2 Jan 2013, at 21:03, Joel Reymont <email@hidden> 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 (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



--
--------------------------------------------------------------------------
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 (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: simulating <enter> in a text field by pressing a button
      • From: Joel Reymont <email@hidden>
References: 
 >simulating <enter> in a text field by pressing a button (From: Joel Reymont <email@hidden>)
 >Re: simulating <enter> in a text field by pressing a button (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: making the most of a symbolic breakpoint
  • Next by Date: Re: simulating <enter> in a text field by pressing a button
  • Previous by thread: Re: simulating <enter> in a text field by pressing a button
  • Next by thread: Re: simulating <enter> in a text field by pressing a button
  • Index(es):
    • Date
    • Thread