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.
For find indexPath in Swift 4 and Swift 5 when calling button,
// First you Add target on button in "cellForRowAt"
cell.myBtn.addTarget(self, action: #selector(self.btnAction(_:)), for: .touchUpInside)
// Add function
func btnAction(_ sender: UIButton) {
let point = sender.convert(CGPoint.zero, to: yourTableView as UIView)
let indexPath: IndexPath! = yourTableView.indexPathForRow(at: point)
print("indexPath.row is = \(indexPath.row) && indexPath.section is = \(indexPath.section)")
}