Re: Changing the behavior of 'Return' in NSTableView
Re: Changing the behavior of 'Return' in NSTableView
- Subject: Re: Changing the behavior of 'Return' in NSTableView
- From: Michael Fey <email@hidden>
- Date: Thu, 12 Jul 2007 09:51:51 -0400
Thanks John. For the sake of completeness and the benefit of other
list members, I received another response off-list that suggested I
try sub-classing NSTableView and override keyDown:
- (void)keyDown:(NSEvent *)event
{
...
if ([event keyCode] == 36) // I'm sure there's a constant
somewhere...
{
// My fake select on Enter.
if ([[self delegate] respondsToSelector: @selector
(tableView:rowSelected:)])
[[self delegate] tableView:self rowSelected:[super
selectedRow]];
}
else
[super keyDown:event];
}
Regards,
Michael Fey
On Jul 12, 2007, at 7:35 AM, John Shockey wrote:
On Jul 12, 2007, at 5:51 AM, Michael Fey wrote:
I have code in place such that when the user adds a row to the
table it automatically begins editing the cell in the first column
of the new row. However, when the user hits the Return key, I'd
like that cell to break out of editing mode and keep the current
row selected instead of the default behavior of moving on to the
next row.
The following worked for me in a program I wrote a while ago.
Have the table's delegate implement:
- (BOOL) control: (NSControl *) control textView: (NSTextView *)
textView doCommandBySelector: (SEL) command
If the control is your table view, and the command is @selector
(insertNewline:), call
[yourWindowWhichYouGetFromSomewhere makeFirstResponder: control];
and return YES
[control window] should be one way to get the window, though in my
case I had it available even more easily.
You can obviously use this method to alter the behavior of many of
the keys bound to specific effects. (For a list of many possible
selectors, see the documentation for NSResponder.)
I hope that helps.
John Shockey
john ATSIGN johncshockey DOT com
_______________________________________________
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:
40partech.com
This email sent to email@hidden
_______________________________________________
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