Question

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

Was it helpful?

Solution

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;
}

OTHER TIPS

Here is a link to the NSTableViewDelegate docs.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top