I have a table view in my VC. Inside the cell there are some lables and buttons. I passed the values in my labels, now i'm trying that when i hit a button that is also in that cell it should increment the value of the label. The value in that label is coming from previous VC. I have made a delegate for it when button is pressed, when button is pressed it should increment the value of label by the first price which is present in it. i'M TRYING to get that cell index path but not geeting it. My code is this, In my cel class i have this protocol,
protocol cartDelegate {
func addTappedInCell(_ cell: CartTableViewCell)
func minusTappedInCell(_ cell: CartTableViewCell)
}
var delegate : cartDelegate?
@IBAction func addBtnTapped(_ sender: Any) {
delegate?.addTappedInCell(self)
}
@IBAction func minusBtnTapped(_ sender: Any) {
delegate?.minusTappedInCell(self)
}
and in my view controller i'm trying this,
extension CartViewController : cartDelegate{
func addTappedInCell(_ cell: CartTableViewCell) {
guard let indexPath = cartTableView?.indexPath(for: cell) else { return }
print(indexPath)
total += 1
cell.totalLbl.text = String(total)
print(cell.priceLbl.text!)
count = "5"
let tPrice = cell.priceLbl.text! + count
print(tPrice)
cell.priceLbl.text = String(tPrice)
subTotalLbl.text = cell.priceLbl.text
}
func minusTappedInCell(_ cell: CartTableViewCell) {
total -= 1
cell.totalLbl.text = String(total)
price = Int(cell.priceLbl.text!)! - Int(count)!
cell.priceLbl.text = String(price)
subTotalLbl.text = cell.priceLbl.text
}
I'm not getting the indexPath of that cell which button is pressed.
This is how my screen looks,