• 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
Properly supporting 'delete' key presses in NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Properly supporting 'delete' key presses in NSTableView


  • Subject: Properly supporting 'delete' key presses in NSTableView
  • From: "Sean McBride" <email@hidden>
  • Date: Mon, 20 Oct 2008 17:07:47 -0400
  • Organization: Rogue Research

Hi all,

In 10.5, NSTableView handles many keypresses automatically: up arrow,
down arrow, page up, page down, home, end, and even 'type select'.

I also need to (robustly!) support the 'delete' key.

Overriding deleteBackward: (from NSResponder) doesn't seem to work.  For
some reason, it is never called.

What is the most correct way to support this?  I need the keypresses
that NSTableView already supports to continue working, and I need to
support custom key bindings (meaning the delete functionality may not be
mapped to the delete key).

My current best is the following, but I don't think it will support
custom keybindings.

- (void)keyDown:(NSEvent*)event
{
	BOOL deleteKeyEvent = NO;

	if ([event type] == NSKeyDown)
	{
		NSString* pressedChars = [event characters];
		if ([pressedChars length] == 1)
		{
			unichar pressedUnichar =
    [pressedChars characterAtIndex:0];

			if ( (pressedUnichar == NSDeleteCharacter) ||
    (pressedUnichar == 0xf728) )
			{
				deleteKeyEvent = YES;
			}
		}
	}

	// If it was a delete key, handle the event specially, otherwise call super.
	if (deleteKeyEvent)
	{
		// This will end up calling deleteBackward: or deleteForward:.
		[self interpretKeyEvents:[NSArray arrayWithObject:event]];
	}
	else
	{
		[super keyDown:event];
	}
}

Thanks for any suggestions,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

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: Properly supporting 'delete' key presses in NSTableView
      • From: Andy Lee <email@hidden>
    • Re: Properly supporting 'delete' key presses in NSTableView
      • From: Corbin Dunn <email@hidden>
  • Prev by Date: Re: Return and Enter don't "behave" in Text Field (Newb)
  • Next by Date: Re: Properly supporting 'delete' key presses in NSTableView
  • Previous by thread: Re: Launchd timeout messages
  • Next by thread: Re: Properly supporting 'delete' key presses in NSTableView
  • Index(es):
    • Date
    • Thread