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

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

    Very Simple getting Index Path swift 4, 5

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! Cell
    cell.btn.tag = indexPath.row
    cell.btn.addTarget(self, action: "buttonTapped:", forControlEvents: 
    UIControlEvents.TouchUpInside)
    

    How to get IndexPath Inside Btn Click :

    func buttonTapped(_ sender: UIButton) {
         print(sender.tag)  
    }
    

提交回复
热议问题