Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTableView + Delete Key

I'm looking for an easy solution to delete NSTableView rows by pushing the delete key.

All I have seen when searching in Google were answers like this: http://likethought.com/lockfocus/2008/04/a-slightly-improved-nstableview/

This seems to me an Engineering solution, but I would like to know if this is the best way. Does any one know a better answer?

like image 564
Leandro Avatar asked Jan 12 '11 12:01

Leandro


1 Answers

There is no need to subclass and catch keyDown in NSViewController.

The Delete menu item in the menu Edit is connected to the selector delete: of First Responder. If there is no Delete menu item, create one and connect it to delete: of First Responder (red cube).

  • Assign a key equivalent to the Delete menu item ( or ⌘⌫)
  • In the view controller implement the IBAction method

    Swift: @IBAction func delete(_ sender: AnyObject)

    Objective-C: -(IBAction)delete:(id)sender

    and put in the logic to delete the table view row(s).

like image 77
vadian Avatar answered Sep 28 '22 03:09

vadian