• 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: performKeyEquivalent & key events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >performKeyEquivalent & key events (From: Chad Armstrong <email@hidden>)

  • Prev by Date: Re: Self contained MetaPackages
  • Next by Date: Awesome Cocoa OpenGL samples (mix Quartz including text with OpenGL)
  • Previous by thread: performKeyEquivalent & key events
  • Next by thread: Re: performKeyEquivalent & key events
  • Index(es):
    • Date
    • Thread