Get section number in custom cell button action

后端 未结 5 1241
北恋
北恋 2021-01-13 23:42

I have a tableView dynamically populated with custom cells in several sections.

In my CustomCell class I have an @IBAction for a custom checkbox button in the cell.

5条回答
  •  Happy的楠姐
    2021-01-14 00:10

    In Swift 3.0, some things are slightly changed like 'CGPointZero' - > 'CGPoint.zero' & 'indexPathForRowAtPoint' -> 'indexPathForRow(at:position)' etc so you can get the real row and section of the tapped button from this code:

    let position: CGPoint = sender.convert(CGPoint.zero, to: self.tableView)
    if let indexPath = self.tableView.indexPathForRow(at: position)
    {
      let section = indexPath.section
      let row = indexPath.row
    }
    

提交回复
热议问题