I am using tableviewcell and within that cell, i am using two UIButtons i.e. btnView and btnEdit. When i tap on btnEdit, i want to get indexPath for this button cell. How do i get ?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DepartmentCell", for: indexPath) as! ShowDepttTVCell
//Set action to buttons
cell.btnView.addTarget(self, action: #selector(btnView), for: .touchUpInside)
cell.btnEdit.addTarget(self, action: #selector(btnEdit), for: .touchUpInside)
return cell
}
@objc func btnView()
{
let viewDepttVC = self.storyboard?.instantiateViewController(withIdentifier: "Detailed Department") as! DetailedDepttVC
self.navigationController?.pushViewController(viewDepttVC, animated: true)
}
@objc func btnEdit()
{
//I want to get the indexpath of this cell button.
print("Selected iNdex : \(r)")
print("Edit")
let editDeptt = self.storyboard?.instantiateViewController(withIdentifier: "Add Department") as! AddDepartmentVC
editDeptt.btnTag = 0
//editDeptt.strDName =
self.navigationController?.pushViewController(editDeptt, animated: true)
}