How to pass UITableView IndexPath to UIButton @selector by parameters in iOS?

前端 未结 5 1534
无人共我
无人共我 2020-12-06 02:34

I have added UIButton in UITableViewCells. I have when the user clicks the button we have get the indexpath to use the values from NSMutableA

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 03:21

    For a tableview with more than one section a simpler solution would be to assign the tag:

    cell.button.tag = indexPath.section * 1000 + indexPath.row
    

    In the event handler use:

    let section = sender.tag / 1000
    let row = sender.tag % 1000
    

    Note that you need to multiply with a larger number than 1000 if any of your sections can contain 1000 or more rows.

提交回复
热议问题