Properly supporting 'delete' key presses in NSTableView
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