0

I am trying to trigger a method everytime a button is clicked in a custom Tableview Cell.

The difficulty is that I have created the custom Tableview cell, but I am unable to programmatically add a selector to it.

In IOS there is a function to "addTarget" but I can't se the equivalent in OSX.

Any ideas?

UKDataGeek
  • 6,338
  • 9
  • 46
  • 63
  • Yes that looks correct although the delegate method below looks like a good solution the duplicate method is simpler – UKDataGeek Aug 05 '16 at 05:56

1 Answers1

0

I did this by defining a NSTableViewCellSelectionDelegate protocol and making my viewController the "selectionDelegate" of each of my cells.

When the VC creates the cells, each cell's selectionDelegate is set to the VC.

Then, each time some action happens in your TableViewCell subclass, it calls its selectionDelegate (theVC). And if you have problems with your VC not knowing which row is being clicked, you can create a row property on your tableviewcells that your VC sets when it creates them for your cells to pass back to the VC when calling their selectionDelegates.

Theme
  • 417
  • 6
  • 18