【问题标题】:Stackview is hidden in reusable tableview cell after inserting cells插入单元格后,Stackview 隐藏在可重复使用的 tableview 单元格中
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 实际上,我只隐藏了一个堆栈视图,其他的东西是 sack 视图中的视图
  • 其实 Stack View 是通过它的内部视图来决定它的内容高度的,如果你把它们全部隐藏起来就看不到了.. 希望你明白了
猜你喜欢
  • 2018-12-21
  • 1970-01-01
  • 1970-01-01
  • 2019-11-10
  • 1970-01-01
  • 2018-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多