I manually start an edit session with a NSTextField after the user clicks in the field by doing the following:

[textField selectText:nil];                     
NSTextView      *currentEditor  = (NSTextView*)[textField currentEditor];
NSPoint         windowLocation  = [theEvent locationInWindow];
NSPoint screenLocation = [[self window] convertBaseToScreen:windowLocation]; NSUInteger characterIndex = [currentEditor characterIndexForPoint:screenLocation]; [currentEditor setSelectedRange:NSMakeRange( characterIndex + 1, 0 )];


I can then alter the text in the field and press return. Once I press return, the delegate of the field does get a controlTextDidEndEditing notification. However, the field still has it's focus ring and if I start typing again, what I type goes into the field.

The first thing I tried was:

- (void) controlTextDidEndEditing:(NSNotification *)aNotification
{
NSLog( @"ResourceItemController: controlTextDidEndEditing: object: %@", [aNotification object] );
    BOOL resigned = [[aNotification object] resignFirstResponder];
NSLog( @"ResourceItemController: controlTextDidEndEditing: resigned: %d", (int)resigned );
}

but, as one likely expects, this did nothing since the NSTextField wasn't the first responder - it's field editor was.

In the documentation for NSControlTextDidEndEditingNotification, the field editor can be obtained via the userInfo dictionary of the notification. So, the next thing I tried was:


- (void) controlTextDidEndEditing:(NSNotification *)aNotification
{
NSLog( @"ResourceItemController: controlTextDidEndEditing: object: %@", [aNotification object] ); id fieldEditor = [[aNotification userInfo] objectForKey:@"NSFieldEditor"];
    resigned = [fieldEditor resignFirstResponder];
NSLog( @"ResourceItemController: controlTextDidEndEditing: resigned: %d", (int)resigned );
}

However, this just results in an exception...

2009-02-23 10:13:55.842 OutlineCollection-VB[24861:813] NSWindow: - _newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.

and the last NSLog call in controlTextDidEndEditing is not executed.


So, how can I properly edit an editing session of a NSTextField?






_______________________________________________

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

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

Reply via email to