开发者

Making a Method be triggered when a row is selected in a Table View

开发者 https://www.devze.com 2022-12-14 00:47 出处:网络
How would I trigger a Method when a row in a Tab开发者_开发百科le View is selected?You need to use NSTableViewDelegate to control what happens when you use a NSTableView. If your relevant view holding

How would I trigger a Method when a row in a Tab开发者_开发百科le View is selected?


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


Here is a link to the NSTableViewDelegate docs.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消