Home > OS >  "Add to cart" button is not is not showing on ProductTbleViewCell
"Add to cart" button is not is not showing on ProductTbleViewCell

Time:01-22

This is my ProductTableViewCell code -

import UIKit

 protocol CartDelegate {
 func updateCart(cell: ProductTableViewCell) }

  class ProductTableViewCell: UITableViewCell {
 weak var myParent:ProductViewController?
 @IBOutlet weak var name: UILabel!
 @IBOutlet weak var price: UILabel!
@IBOutlet weak var imagename: UIImageView!
@IBOutlet weak var addToCartButton: UIButton!

  var delegate: CartDelegate?

override func awakeFromNib() {
 super.awakeFromNib()
// Initialization code

  addToCartButton.layer.cornerRadius = 5
  addToCartButton.clipsToBounds = true
   }

  func setButton(state: Bool) {
  addToCartButton.isSelected = state
addToCartButton.backgroundColor = (!addToCartButton.isSelected) ? .black : .red
}

  @IBAction func addToCart(_ sender: Any) {
    setButton(state: !addToCartButton.isSelected)
      self.delegate?.updateCart(cell: self)
     }
  }

the labels and buttons are connected properly: as shown below storybord imageL-

enter image description here

But the add to cart button(the button in red) does not show in the simulator as shown below:-

enter image description here

How to fix it ?

CodePudding user response:

You need to give proper constraints to both label and button and give Row Height to the Table view cell.

Check Screenshot here

Another Screenshot of row height

  •  Tags:  
  • Related