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

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

    Swift 4 Solution:

    You have a button (myButton) or any other view in cell. Assign tag in cellForRowAt like this

    cell.myButton.tag = indexPath.row
    

    Now in you tapFunction or any other. Fetch it out like this and save it in a local variable.

    currentCellNumber = (sender.view?.tag)!
    

    After this you can use anywhere this currentCellNumber to get the indexPath.row of selected button.

    Enjoy!

    0 讨论(0)
提交回复
热议问题