On 23.02.2009, at 16:20, Eric Gorr wrote:

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

[snip]


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?

I had the same problem using a set of NSCell objects in one NSView.
You could try:

[[self window] endEditingFor:nil];

This is described as a last resort to abort editing in the NSWindow class reference. It's not recommened, because you first need to save the textStorage contents.

I ended up looking for the controlView using a loop to traverse supervies:

[[self window] makeFirstResponder:nil];

NSView *v = fieldEditor;
while (v && ([v superview] != [self controlView]))
  v = [v superview];

[v removeFromSuperview];

(All typed in mail)

Regards,
Patrick
_______________________________________________

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