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

Stop edit session with a NSTextField


  • Subject: Stop edit session with a NSTextField
  • From: Eric Gorr <email@hidden>
  • Date: Mon, 23 Feb 2009 10:20:58 -0500

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 (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: Patrick Mau <email@hidden>
  • Prev by Date: RE: Populating a new SQLite Core Data store with default data
  • Next by Date: Re: Stop edit session with a NSTextField
  • Previous by thread: Re: [Q] Re: NSPersistentStore -addPersistentStoreWithType
  • Next by thread: Re: Stop edit session with a NSTextField
  • Index(es):
    • Date
    • Thread