objective c - Alternative option of UIButton addTarget:action:forControlEvents: method in IOS -


i know question has been asked many times want pass custom object argument on clicking button.

uibutton addtarget:action:forcontrolevents: doesn't allow important me can further on basis of custom objects.

if alternative add target possible, please give solution.

the code this:

custom object:

headerdata *cell ; 

button:

_forward =[uibutton buttonwithtype:uibuttontyperoundedrect]; [_forward settitle:@"f" forstate:uicontrolstatenormal]; _forward.frame = cgrectmake(300, (_cell_height-_label_height)/2, 10 ,_label_height);] [_forward addtarget:web action:@selector(functionname:) forcontrolevents:uicontroleventtouchupinside];  

and function called on clicking uibutton _forward is:

-(void)functionname:(uibutton *)sender{     //code further programming on basis of cell. } 

you make custom subclass of uibutton:

@interface customdatabutton : uibutton @property (nonatomic, strong) id userdata; @end 

then in functionname, can pull data out:

-(void)functionname:(uibutton *)sender  {     if ([sender iskindofclass:[customdatabutton class]])     {         id customdata = ((customdatabutton *) sender).userdata;     } } 

caveat: written without ide. watch out typos etc.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -