• 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: How to end table cell editing by keyboard (return/enter)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to end table cell editing by keyboard (return/enter)?


  • Subject: Re: How to end table cell editing by keyboard (return/enter)?
  • From: Javigator <email@hidden>
  • Date: Mon, 4 Jul 2005 09:37:27 +0200

Ondra,

2005/7/4, Javigator <email@hidden>:

> On 3.7.2005, at 16:18, <email_removed> wrote:
>
>  > I have a NSTableView setup with a NSTableColumn which consists of
>  > the default NSTextFieldCell. The table is populated using a
>  > NSArrayController (bindings). I allow editing of the entries in the
>  > column via double click and (in another case) sending
>  > editColumn:row:withEvent:select: to the table view.
>  >
>  > What I want: Editing a cell and pressing return ends the editing,
>  > setting the selection to the edited entry. Best case: the app/
>  > controller/whatever gets notified about this event.
>
> The impossibility to do this cleanly is, far as I know, one of a
> surprisingly small number of faults in the Cocoa-based GUI.
>
> Of course, in a dynamic object system anything goes, albeit sometimes
> kinda ugly way :)
>
> The solution looks kind of like this (it's possible there's a better
> one: this one used to be arguably the best available a few years ago
> -- meantime API was improved, *perhaps* making this hack obsolete):
>
> @interface OCSExtraSelectionTableView:NSTableView @end
> @implementation OCSExtraSelectionTableView
> // changes the editing behaviour NOT to select the next line if Enter
> gets pressed
> -(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=[NSMutableDictionary
> dictionaryWithDictionary:[notification userInfo]];
>            [newUserInfo setObject:[NSNumber
> numberWithInt:NSIllegalTextMovement] forKey:@"NSTextMovement"];
>            [super textDidEndEditing:[NSNotification
> notificationWithName:[notification name] object:[notification object]
> userInfo:newUserInfo]];
>            // For some reason we lost firstResponder status when when
> we did the above.
>            [[self window] makeFirstResponder:self];
>        } else [super textDidEndEditing:notification];
> }
> +(void)load {
>      [self poseAsClass:[self superclass]];
> }
> @end
>
> ---
> Ondra Čada
> OCSoftware:    <email_removed>              http://www.ocs.cz
> private        <email_removed>            http://www.ocs.cz/oc

 I don't care if your hack is a hack as long as it works for me. :-)

Unfortunately, the custom NSTableView class breaks populating the
table using bindings and a NSArrayController - the table is empty
(switching back to native NSTableView and it works like a charm). Any
clues why?

Joern.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: DotMacKit 2.0?
  • Next by Date: Radar/Bug Reporter data base is screwed?
  • Previous by thread: Re: How to end table cell editing by keyboard (return/enter)?
  • Next by thread: Programmatic control of Core Data search field
  • Index(es):
    • Date
    • Thread