Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTableView single click action

How to capture the event of single-clicking on a row of an NSTableView and trigger an action? (Idealy, it should trigger the action for left clicks only, not right clicks, but this is not required.)

Implementing -tableViewSelectionDidChange of the table view's delegate is close to what I want. However, if a row is currently selected, clicking on that row again doesn't call -tableViewSelectionDidChange since the selection didn't change.

like image 472
Ethan Avatar asked Mar 29 '15 03:03

Ethan


1 Answers

Connect the selector action event on the table view (better from interface designed), then

- (IBAction)onAction:(id)sender {
    NSTableView* tableView = (NSTableView*)sender;
    // use tableView.selectedColumn/tableView.selectedRow to get the selection
}

You can also connect it from code if you want fro viewDidLoad:

[self.tableView setAction:@selector(onAction:)];
like image 101
Corneliu Maftuleac Avatar answered Oct 16 '22 19:10

Corneliu Maftuleac