2

I have a tableview for showing some products, the products may or not have a discount, the discounts (max 2) are grouped in a stackView, so in code I hide or show the stack view if the product have a discount.

The problem comes when I insert a new cell, suddenly the cell that holds a product with discount doesn't have the stack view visible.

I tried with the 2 methods for dequeue cells, when I use,

tableView.dequeueReusableCell(withIdentifier:, forIndexPath)

the problem occurs when Inserting but when I use,

tableView.dequeueReusableCell(withIdentifier:)

the problem at inserting disappear, but occurs again when I scroll down to make the cell not visible and scroll back.

This is the code in cell for row:

let basicCell = tableView.dequeueReusableCell(withIdentifier: "basicCell") as! BasicCell
        if product.discounts{
            basicCell.discountType = DiscountType.lineDiscount
        }else{
            basicCell.discountType = DiscountType.none
        }
        basicCell.configureCellType()

        return basicCell

And the code of configureCellType():

func configureCellType(){
    switch discountType! {
    case .none:
        discountStackView.isHidden = true
    case .lineDiscount:
        groupDiscountView.isHidden = true
    case .groupDiscount:
        lineDiscountView.isHidden = true
    case .bothDiscounts: break
    }
}

1 Answers1

2

well the problem is actually in your configureCellType() function. As each case is hiding a stack view .. Check it out

Hobbit
  • 601
  • 1
  • 9
  • 22
  • Actually, I hide only one stack view the other stuff are the views inside the sack view – user3407533 May 17 '17 at 17:26
  • Actually Stack View determine its content height by its inner views, if you completely hide them all, it will not be visible.. I hope you got that – Hobbit May 17 '17 at 17:35