Re: NSTextField controlTextDidEndEditing
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