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
2009-12-16 17:52:52
I need it for NSTableView.
Joshua
2009-12-16 18:20:29
You need to read a lot of documentation.
Azeem.Butt
2009-12-16 18:35:18
Why's that then?
Joshua
2009-12-16 18:36:38
Because this is a question whose answer you clearly put no effort into finding whatsoever.
Azeem.Butt
2009-12-16 18:39:58
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
2009-12-16 23:19:56
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
2009-12-16 20:51:54