2

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

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

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

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
    }
}
4

1 回答 1

2

好吧,问题实际上出在您的configureCellType()功能中。由于每种情况都隐藏了一个堆栈视图..检查一下

于 2017-05-17T17:21:36.927 回答