• 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: NSTextField controlTextDidEndEditing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField controlTextDidEndEditing


  • Subject: Re: NSTextField controlTextDidEndEditing
  • From: Mike Abdullah <email@hidden>
  • Date: Sat, 6 Mar 2010 01:21:01 +0000

On 6 Mar 2010, at 01:00, Ulai Beekam wrote:

>
> I have a delegate of NSTextField that uses the controlTextDidEndEditing: method to do some stuff when the editing has finished.
>
> However, there are (as far as I can imagine) two types of possible scenarios under which the editing finishes: 1) the user hits return. in this case, the focus stays on the text field. 2) the user presses tab or clicks someplace else, in which case the text field loses focus.
>
> My question is: What is the proper way to know *within the controlTextDidEndEditing: delegate method* which of the two scenarios occurred (or will occur? i suppose it has already occurred since it's a "Did" method)?
>
> This is how I'm currently doing it, and it is not working properly:
>
> - (void)controlTextDidEndEditing:(NSNotification *)aNotification
> {
>  NSTextField *textField = [aNotification object];
>  NSTextView *fieldEditor = [[aNotification userInfo] objectForKey:@"NSFieldEditor"];
>    if ([[textField window] firstResponder] == fieldEditor)
>    NSLog(@"focus lost");
>  else
>    NSLog(@"focus retained");
> }
>
> This works only in that if the user *clicks* outside the text field, "focus lost" is printed, and if the user hits return, "focus retained" is printed. However, this *fails* when I tab out of the text field, in which case "focus retained" is printed, which obviously indicated that my way of doing this sucks.
>
> So I'm all out of luck. Any ideas?

NSText handles this properly; when it posts an NSTextDidEndEditingNotification, that includes NSTextMovement as a key. I'm not sure if NSControlTextDidEndEditingNotification is kind enough to pass that on too, or if you'll have to listen out for the original notification from the field editor._______________________________________________

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: NSTextField controlTextDidEndEditing
      • From: Ulai Beekam <email@hidden>
References: 
 >NSTextField controlTextDidEndEditing (From: Ulai Beekam <email@hidden>)

  • Prev by Date: NSTextField controlTextDidEndEditing
  • Next by Date: Re: How a window was closed?
  • Previous by thread: NSTextField controlTextDidEndEditing
  • Next by thread: RE: NSTextField controlTextDidEndEditing
  • Index(es):
    • Date
    • Thread