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

前端 未结 19 2615
梦如初夏
梦如初夏 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:04

    Try using #selector to call the IBaction.In the cellforrowatindexpath

                cell.editButton.tag = indexPath.row
            cell.editButton.addTarget(self, action: #selector(editButtonPressed), for: .touchUpInside)
    

    This way you can access the indexpath inside the method editButtonPressed

    func editButtonPressed(_ sender: UIButton) {
    
    print(sender.tag)//this value will be same as indexpath.row
    
    }
    

提交回复
热议问题