Backtabbing into an NSTableView
Backtabbing into an NSTableView
- Subject: Backtabbing into an NSTableView
- From: K.Darcy Otto <email@hidden>
- Date: Fri, 5 Jun 2009 17:45:56 -0700
I have an application where a 2-column NSTableView subclass is the
main visual element. Users can select rows only, not columns. When
the user has a row selected, and presses [Tab], the table
automatically starts editing the first column. I want to make it so
that when the user has a row selected, and presses [Shift+Tab] (i.e.,
a back-tab), the table automatically starts editing the second column
(without the following code, it highlights the second-column cell, but
does not begin editing). Here is the code in the subclass that I'm
currently using to do this:
-(void)keyDown:(NSEvent *)theEvent
{
if ([theEvent keyCode] == 48) // 48 is the key code for back-tab
{
[self editColumn:1 row:[self selectedRow] withEvent:nil select:YES];
}
[super keyDown:theEvent];
}
My question is, is there a more high-level way to do this? I found
"48" corresponding to the back-tab by using NSLog to look at different
key codes. I tried replacing "48" "NSBacktabTextMovement" and
"NSBackTabCharacter" ... no dice, presumably because both
NSBacktabTextMovement and NSBackTabCharacter are unicode constants,
and -keyCode returns an unsigned short. I suspect I could run this
through UCKeyTranslate(), but when playing around with this, I lost my
nerve in the face of the 10 parameters that function requires.
According to documentation for NSEvent's -keyCode, the number is
supposed to be "hardware-independent". If this means what I think it
means, 48 should be the back-tab in all situations, right? So, the
above code should be fine?
Incidentally, I have brought about the same effect by the following
code:
- (void)keyDown:(NSEvent *)theEvent
{
[self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
[super keyDown:theEvent];
}
-(void)insertBacktab:(id)sender
{
[self editColumn:1 row:[self selectedRow] withEvent:nil select:YES];
}
Is this, in some way, better than the first solution? Or is there
some better way to do what I'm trying to do? Thanks.
_______________________________________________
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