• 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: Stop edit session with a NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stop edit session with a NSTextField


  • Subject: Re: Stop edit session with a NSTextField
  • From: Patrick Mau <email@hidden>
  • Date: Mon, 23 Feb 2009 16:44:16 +0100


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 (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: Stop edit session with a NSTextField
      • From: Eric Gorr <email@hidden>
References: 
 >Stop edit session with a NSTextField (From: Eric Gorr <email@hidden>)

  • Prev by Date: Stop edit session with a NSTextField
  • Next by Date: Re: Stop edit session with a NSTextField
  • Previous by thread: Stop edit session with a NSTextField
  • Next by thread: Re: Stop edit session with a NSTextField
  • Index(es):
    • Date
    • Thread