i have used tableview in storyboard. in tableview have added cell. each row cell contains labels , buttons.
now:
i want make row clickable buttons on cell clickable.
i have tried using storyboard not working.
your error drag button directly uiviewcontroller,that not work. because prototype cell.
what can
- set tag button,for example 11
add target in
cellforrowatindex
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! uitableviewcell let button = cell.viewwithtag(11) as? uibutton if button != nil{ button?.addtarget(self, action: "clicked:", forcontrolevents: uicontrolevents.touchupinside) } return cell }
get button action , index
func clicked(sender:uibutton){ let point = sender.convertpoint(cgpointzero, toview:self.tableview) let indexpath = self.tableview.indexpathforrowatpoint(point) println("clicked \(indexpath!.row)") }
Comments
Post a Comment