ios - How to make cell clickable also the buttons on cell will be clickable in swift -


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

  1. set tag button,for example 11
  2. 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 } 
  3. 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