[ad_1]
I am engaged on a procuring app undertaking the place prospects can flick thru merchandise and add them to their cart, however am having bother determining find out how to deal with button presses throughout the tableViewCell. They manner I would like it to work is that when the empty circle button is pressed, the picture adjustments to a crammed circle with a checkmark, and the product inside that cell is added to the purchasers “cart”. The “cart” consists of two arrays merchandise and portions held inside my CustomerOrder object.
Here is what the tableView appears like:
Here is my code up to now:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductToBuyCell") as! ProductToBuyCell
//Configure the Choice Button
cell.selectButton.tag = indexPath.row
cell.selectButton.addTarget(self, motion: #selector(ItemSelected), for: .touchUpInside)
let product = productsArray[indexPath.row]
//configure cell
cell.productImg.picture = product.productPhoto
cell.productImg.contentMode = .scaleAspectFit
cell.productName.textual content = product.Identify
cell.worth.textual content = "$(product.worth)"
return cell
}
// func for when the selectButton is tapped
// tag is the same as indexPath.row
@objc func ItemSelected(sender: UIButton) {
sender.imageView?.picture = UIImage(systemName: "checkmark.circle.fill")
let product = productsArray[sender.tag]
newOrder.merchandise.append(product)
newOrder.portions.append(1)
}
So if somebody may please clarify find out how to correctly deal with IBAction like occasions which might be attributable to parts inside a UITableViewCell that might be very a lot appreciated.
[ad_2]

