• 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: NSTableView : editable cells & return key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView : editable cells & return key


  • Subject: Re: NSTableView : editable cells & return key
  • From: Kurt Revis <email@hidden>
  • Date: Wed, 16 Jan 2002 15:51:17 -0800

On Wednesday, January 16, 2002, at 03:36 PM, Bruno Blondeau wrote:

I'm using a NSTableView which text cells are user-editable.

However, when a user presses the return key, the edit field moves to the
next row, which is not the behavior a Mac user expects from most
applications. (the row should remain selected, not select the next row and
start editing it).

This question has come up many times before on this list; I recommend checking the archives.

Anyway, here's what I use. (I admit that I can't remember if this was the "best" way or not.) Subclass NSTableView and override this method:

- (void)textDidEndEditing:(NSNotification *)notification;
{
if ([[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement) {
// This is ugly, but just about the only way to do it. NSTableView is determined to select and edit something else, even the text field that it just finished editing, unless we mislead it about what key was pressed to end editing.
NSMutableDictionary *newUserInfo;
NSNotification *newNotification;

newUserInfo = [NSMutableDictionary dictionaryWithDictionary:[notification userInfo]];
[newUserInfo setObject:[NSNumber numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];
newNotification = [NSNotification notificationWithName:[notification name] object:[notification object] userInfo:newUserInfo];
[super textDidEndEditing:newNotification];

// For some reason we lose firstResponder status when when we do the above.
[[self window] makeFirstResponder:self];
} else {
[super textDidEndEditing:notification];
}
}

--
Kurt Revis
email@hidden


  • Follow-Ups:
    • Re: NSTableView : editable cells & return key
      • From: Manfred Lippert <email@hidden>
References: 
 >NSTableView : editable cells & return key (From: Bruno Blondeau <email@hidden>)

  • Prev by Date: NSTableView : editable cells & return key
  • Next by Date: Re: Output from NSTask and modal window
  • Previous by thread: NSTableView : editable cells & return key
  • Next by thread: Re: NSTableView : editable cells & return key
  • Index(es):
    • Date
    • Thread