I have a tableview with buttons and I want to use the indexpath.row when one of them is tapped. This is what I currently have, but it always is 0
var point = Int()
func buttonPressed(sender: AnyObject) {
let pointInTable: CGPoint = sender.convertPoint(sender.bounds.origin, toView: self.tableView)
let cellIndexPath = self.tableView.indexPathForRowAtPoint(pointInTable)
println(cellIndexPath)
point = cellIndexPath!.row
println(point)
}
You have a button (myButton) or any other view in cell. Assign tag in cellForRowAt like this
Now in you tapFunction or any other. Fetch it out like this and save it in a local variable.
After this you can use anywhere this currentCellNumber to get the indexPath.row of selected button.
Enjoy!
For
Swift2.1
I found a way to do it, hopefully, it'll help.