views:

68

answers:

3

How would I trigger a Method when a row in a Table View is selected?

+1  A: 

Am I missing something? Just call it in the following delegate method: didSelectRowAtIndexPath

ennuikiller
I need it for NSTableView.
Joshua
You need to read a lot of documentation.
Azeem.Butt
Why's that then?
Joshua
Because this is a question whose answer you clearly put no effort into finding whatsoever.
Azeem.Butt
+3  A: 

It helps if you actually look at the docs

Azeem.Butt
NSTableViewSelectionDidChangeNotification?
Joshua
That's a notification name (which is why it ends in “Notification”). Observing for the notification is one way, but being the delegate is easier.
Peter Hosey
A: 

You need to use NSTableViewDelegate to control what happens when you use a NSTableView. If your relevant view holding the table is named MyViewController, your interface (.h) file should start like this:

@interface MyViewController : NSObject <NSTableViewDelegate> {

And then in your implementation (.m) file, have this:

- (id)init {
     [super init];
     myTableView.delegate = self;
     return self;
}

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)rowIndex {
     NSLog(@"%i tapped!", rowIndex);
     return YES;
}
Chris Long