我有一个用于显示某些产品的表格 View ,这些产品可能有折扣,也可能没有折扣,折扣(最多 2 个)分组在 stackView 中,因此在代码中,如果产品有折扣,我会隐藏或显示堆栈 View 。
当我插入一个新单元格时,问题就出现了,突然间,包含折扣产品的单元格没有可见的堆栈 View 。
我尝试了两种使单元出队的方法, 当我使用时,
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()
函数中。
由于每个案例都隐藏了一个堆栈 View ..检查一下
关于ios - 插入单元格后,Stackview 隐藏在可重用的表格 View 单元格中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44030841/