ios - Pass indexPath.row to button in a custom cell using SWIFT -


i have simple table view, custom cell build in it, custom cell has 2 buttons ( later used down vote , upvote buttons ), there way pass indexpath.row value button, in order me identify cell button clicked?

tablewviewcontroller.swift

 override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) customtableviewcell          cell.piadatitulo.text = "lorem ipsum"         cell.piadadescription.text = "lorem ipsum dolor sit amet, consectetur adipiscing elit. aenean commodo volutpat lectus, vitae semper tortor finibus at. cras erat ligula, egestas sed tincidunt eget, condimentum maximus lectus. aenean varius semper tellus, id congue lacus pretium a"           return cell     } 

customtableviewcell.swift

@iboutlet weak var piadatitulo: uilabel! @iboutlet weak var piadadescription: uilabel!  @ibaction func piadaupvote(sender: anyobject) {     println("upvote clicked") }  @ibaction func piadadownvote(sender: anyobject) {     println("downvote clicked") } 

simple table view

screw tags. use extension easy find of indexpath of button's cell.

// mark: - uitableview extension uitableview {     func indexpathforview (view : uiview) -> nsindexpath? {         let location = view.convertpoint(cgpointzero, toview:self)         return indexpathforrowatpoint(location)     } }  @ibaction func pressedbutton(sender: anyobject) {     // button press     let button = sender as! uibutton     var indexpath = self.tableview.indexpathforview(button)!      // thangs } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -