Re: key presses in tableview delegate?
Re: key presses in tableview delegate?
- Subject: Re: key presses in tableview delegate?
- From: Craig Courtney <email@hidden>
- Date: Sat, 29 Dec 2001 12:48:49 -0500
I just figured this out the other day myself. You need to use the
keyDown event on a responder. The following is the code I used as a
sample. I pulled the shell of this code off previous messages in the
list and added it to my WindowController. My window was a simple one
with just the TableView on it other wise you would have to do more
checking to see if it was appropriate to catch the delete key. I have
not seen multiple characters returned yet but have left in that code
just in case. Hope this at least sets you in the right direction.
Good Luck,
Craig Courtney
- (void)keyDown:(NSEvent *)theEvent
{
NSString *characters;
unichar c;
unsigned int characterIndex, characterCount;
bool passOnEvent = YES;
int selectedRow = [table selectedRow];
// There could be multiple characters in the event.
characters = [theEvent charactersIgnoringModifiers];
characterCount = [characters length];
for (characterIndex = 0; characterIndex < characterCount;
characterIndex++)
{
c = [characters characterAtIndex: characterIndex];
switch(c)
{
case NSDeleteFunctionKey:
if (selectedRow > -1) {
[cardStore removeCardForID:[cardIDs
objectAtIndex:selectedRow]];
passOnEvent = NO;
}
break;
}
}
if (passOnEvent) {
[super keyDown:theEvent];
}
}
On Saturday, December 29, 2001, at 01:14 AM, cocoa-dev-
email@hidden wrote:
Message: 11
Date: Fri, 28 Dec 2001 21:51:27 -0800
Subject: key presses in tableview delegate?
From: email@hidden
To: Cocoa Dev Mailing List <email@hidden>
i saw several questions like this in the archive, but no answers that
didn't involve subclassing NSTableView. i know how to get keys in a
subclass, but i was hoping there was some magic to get them without
going that far?
i notice that when you select a tableview row and press the delete key
for example, it beeps... meaning that a method was dispatched that no
one in the view hierarchy handled... is there any way to handle that
message in the delegate?
(i'm just trying to have the delete key delete rows in my table...
should be easy?)