• 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: Backtabbing into an NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Backtabbing into an NSTableView


  • Subject: Re: Backtabbing into an NSTableView
  • From: "K. Darcy Otto" <email@hidden>
  • Date: Sat, 6 Jun 2009 11:29:45 -0700

An update on this question. It turns out the first bit of code does not work after all, because 48 is the keyCode for [Tab] and [Shift +Tab]. I needed to change the code to the following:

-(void)keyDown:(NSEvent *)theEvent
{
if ([theEvent keyCode] == 48 && ([theEvent modifierFlags] & NSShiftKeyMask)) // 48 is the tab key
{
[self editColumn:1 row:[self selectedRow] withEvent:nil select:YES];
return;
}
[super keyDown:theEvent];
}


Without the "return;" there is a "bing". To tell the truth, I'm not sure why I get the "bing." I'm guessing that it has something to do with the responder chain, but the thing is, the table can respond to a backtab.

The second bit of code (Code B) works, but it gives a "bing" at every keypress. Again, I'm thinking this has something to do with the responder chain; but I'm not clear what. Any ideas?

On 5-Jun-09, at 5:45 PM, K.Darcy Otto wrote:

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:

(Code A) -(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:

(Code B) - (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


  • Follow-Ups:
    • Re: Backtabbing into an NSTableView
      • From: Vadim <email@hidden>
References: 
 >Backtabbing into an NSTableView (From: K.Darcy Otto <email@hidden>)

  • Prev by Date: Re: crashing web browser with openURL call
  • Next by Date: crash in -[_NSArrayControllerTreeNode _safeNodeAtIndexPath:]
  • Previous by thread: Backtabbing into an NSTableView
  • Next by thread: Re: Backtabbing into an NSTableView
  • Index(es):
    • Date
    • Thread