Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger an action from a NSTableCellView in view based NSTableView when using bindings

I'm facing a problem with a view-based NSTableView running on 10.8 (target is 10.7, but I think this is not relevant).

I'm using an NSTableView, and I get content values for my custom NSTableCellView through bindings. I use the obejctValue of the NSTableCellView to get my data.

I added a button to my cell, and I'd like it to trigger some action when clicked. So far I have only been able to trigger an action within the custom NSTableCellView's subclass.

I can get the row that was clicked like this, using the chain:

NSButton *myButton = (NSButton*)sender;    

NSTableView *myView = (NSTableView*)myButton.superview.superview.superview;

NSInteger rowClicked = [myView rowForView:myButton.superview];

From there I don't know how to reach my App Delegate or controller where the action is defined.

As I am using cocoa bindings, I do not have a delegate on the NSTableView that I could use to trigger my action.

Do you have any idea how I could talked back to controller ?

Many thanks in advance!

like image 348
Olivier Pallière Avatar asked Sep 04 '12 15:09

Olivier Pallière


1 Answers

Although you are using bindings you can still set your controller as the delegate for your tableview in the interface builder.

I see that you already are able to access the table view from inside your cell. The next task must be simple, just set the table view delegate as the target for your button's action.

like image 106
Suhas Avatar answered Oct 07 '22 11:10

Suhas