objective c - How do I send the tag of a NSButtonCell together with his action? -


i have nstableview several columns. column made nsbuttoncells. each nsbuttoncell has specific tag. tag should used inside action method specify cell invoked method.

setting tag cell useless in case, because sender object passed action nstableview , not nsbuttoncell.

cell = [[nsbuttoncell alloc] init];                 [cell setaction:@selector(openscreen:)];                 [cell settag:tag];                 [cell settarget:self];   -(void)openscreen:(id)sender //this sender nstableview, can't tag of cell 

my first recommendation switch view-based table views. in case, problem largely goes away, since sender nsbutton instance, not table view.

if can't that, question: how compute tag want use cell? rather using astoria's answer (with corrections per comment), can use same logic used compute tag given row,column compute value purposes of action method.

think it: cell-based table view typically reuses 1 cell entire column. configures cell setting object value (obtained data source or through bindings) , lets delegate configure more calling -tableview:willdisplaycell:fortablecolumn:row:. if cell being assigned tag, that's done @ point, it's based, somehow, on row , column.

rather asking table view prepared cell, goes through of rigmarole, can feed clickedrow , clickedcolumn same logic use assign tag in first place.

another approach use bindings. cell-based table view, when column configured use nsbuttoncell, column has action invocation bindings. there's target, bind target , specify selector, , there's argument, passed argument selector. in case, selector not receive "sender"; receives generic argument. if table column bound array controller data, can bind argument array controller, too. can use same or different model key path.

basically, in case, don't pass information can affected row, directly pass data or object being represented row. like, if table represents employees, can pass actual employee instance action method , don't need bunch of indirect lookup using rows, columns, tags, etc. find employee operate on.

you can use bindings approach in view-based table view, bind actual button object , use nstablecellview's objectvalue argument.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -