Hi I have a custom UITableViewCell with three buttons to handle a shopping cart function, Plus,Minus and Delete button and I need to know which cell has been touched.
SWIFT 4.*
It can be done like following way too, Not required much coding and delegation, Simple and easy.
Put following code in cellForItemAt for UICollectionView or in cellForRowAt for UITableView
cell.btn.tag = indexPath.row
cell.btn.addTarget(self, action: #selector(buttonSelected), for: .touchUpInside)
And your Method will be
@objc func buttonSelected(sender: UIButton){
print(sender.tag)
}
Thats all.