插入单元格后,Stackview 隐藏在可重用的 tableview 单元格中

Stackview is hidden in reusable tableview cell after inserting cells

我有一个用于显示某些产品的表格视图,这些产品可能有也可能没有折扣,折扣(最多 2 个)被分组在一个 stackView 中,所以在代码中,如果产品有折扣,我会隐藏或显示堆栈视图折扣。

当我插入一个新的单元格时,问题就来了,突然间,持有折扣产品的单元格没有可见的堆栈视图。

我尝试了两种出列单元格的方法, 当我使用时,

tableView.dequeueReusableCell(withIdentifier:, forIndexPath)

插入时出现问题 但是当我使用时,

tableView.dequeueReusableCell(withIdentifier:)

插入时的问题消失了,但当我向下滚动以使单元格不可见并向后滚动时再次出现。

这是行单元格中的代码:

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

        return basicCell

以及configureCellType()的代码:

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

好吧,问题实际上出在您的 configureCellType() 函数中。 由于每个案例都隐藏了一个堆栈视图 .. 检查一下