【发布时间】:2017-05-17 16:57:48
【问题描述】:
我有一个用于显示某些产品的表格视图,这些产品可能有折扣,也可能没有折扣,折扣(最多 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
}
}
【问题讨论】:
-
请展示您的
cellForRow实现。 -
在 return 语句之前调用 cell.layoutIfNeeded() ..
-
@Umer 没用
-
在返回基本单元之前,请尝试 cell.setNeedsLayout(), cell.layoutIfNeeded()
-
对于将来可能遇到此问题的任何人,解决方案是在所有情况下将 stackview hidden 设置为 false,但 .none!感谢大家的帮助
标签: ios swift uitableview tableviewcell stackview