How to get the indexpath.row when an element is activated?

前端 未结 19 2749
梦如初夏
梦如初夏 2020-11-21 23:30

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 =         


        
19条回答
  •  感动是毒
    2020-11-22 00:02

    In Swift 4 , just use this:

    func buttonTapped(_ sender: UIButton) {
            let buttonPostion = sender.convert(sender.bounds.origin, to: tableView)
    
            if let indexPath = tableView.indexPathForRow(at: buttonPostion) {
                let rowIndex =  indexPath.row
            }
    }
    

提交回复
热议问题