Re: performKeyEquivalent & key events
Re: performKeyEquivalent & key events
- Subject: Re: performKeyEquivalent & key events
- From: Ryan Bates <email@hidden>
- Date: Mon, 16 Feb 2004 13:38:48 -0800
On Feb 16, 2004, at 11:02 AM, Chad Armstrong wrote:
I have a list of items in a table, and when a user hits the Delete or
Backspace key, I want the highlighted items in the list to disappear.
What would be the best way to implement this? I am assuming that I
will need to use performKeyEquivalent at some point. I also have a
button which can be clicked to delete the items from the list, but
that also has another key binding, other than Delete or Backspace.
I suggest you subclass NSTableView and listen for a key down event. If
it's the delete key then you can send a message to the dataSource
object (or any other object the table view has contact with). For
example:
// In NSTableView subclass
- (void)keyDown:(NSEvent *)event
{
// You may want to beef this up to check for modifier flags, etc.
if ([[event characters] characterAtIndex:0] == NSDeleteCharacter
&& [[self dataSource]
respondsToSelector:@selector(removeSelectedItemsInTableView:)]
&& [self numberOfSelectedRows] > 0) {
[[self dataSource] removeSelectedItemsInTableView:self];
} else {
// Pass on the key event
[super keyDown:event];
}
}
Note: code is untested.
Here's a link to an archived thread which gives a little more info:
<
http://cocoa.mamasam.com/COCOADEV/2002/07/2/40655.php>
Ryan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.