我正在使用tableviewcell并在该单元格内,我使用两个UIButtons,即btnView和btnEdit。当我点击btnEdit时,我想获得此按钮单元格的indexPath。我怎么得到?
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)
}
答案 0 :(得分:0)
检查以下代码:
@Transactional
答案 1 :(得分:0)
两种方式
第一。
cell.btnView.tag = indexPath.row
将@objc func btnView()
更改为@objc func btnView(btn: UIButton)
所以你可以使用btn.tag
秒。这是一种了解细胞使用UIResponder的方法 My blog