ios - how to call method in controller from a UIButton in a UITableViewCell -


i have uitableview own uitableviewcells, contains uibutton. uitableview added viewcontroller @ runtime. works fine way see button in cells. when pressing button action called in uitableviewcell.

now. how can call method in viewcontroller, when button pressed in cell ?

in uitableviewcell class have button in cell:

let framebutton_in_cell:cgrect=cgrectmake(0, 0, 40,40);     button_in_cell.frame=framebutton_in_cell;     button_in_cell.addtarget(self, action: "buttonactiontext:", forcontrolevents: uicontrolevents.touchupinside)     button_in_cell.tag = 1;     var image2 = uiimage(named: "book");     button_in_cell.setimage(image2, forstate: .normal)     var transparent2:uicolor=uicolor(red: 0, green: 0, blue: 0, alpha: 0.0);      contentview.addsubview(button_in_cell); 

and have function buttonactiontext:

func buttonactiontimeline(sender:uibutton!) {     var btnsendtag:uibutton = sender     //do } 

my uitableview added @ runtime uiviewcontroller:

 override func viewdidload() {         super.viewdidload()         let fsearchresulty:cgfloat=fbuttonheight+fbuttony;         searchresults.frame = cgrectmake(0, fsearchresulty, screenwidth, screenheight-fsearchresulty);         searchresults.delegate      =   self;         searchresults.datasource    =   self;         searchresults.registerclass(cellresult.self, forcellreuseidentifier: "cell");         self.view.addsubview(searchresults); 

now call method in viewcontroller insteed of method in uitableviewcell. how can achieve ?

just don't add target uitableviewcell class instead add in cellforrowatindexpath method

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cellidentifier", forindexpath: indexpath) as! somecustomcell      cell.button_in_cell.addtarget(self, action: "viewcontrollermethod:", forcontrolevents: uicontrolevents.touchupinside)  } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -