ios - 插入单元格后,Stackview 隐藏在可重用的表格 View 单元格中

标签 ios swift uitableview stackview

我有一个用于显示某些产品的表格 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/

相关文章:

ios - 音频框架困惑

ios - 在 Swift 3 中使用带有动态 URL 的 AVAudioPlayer 导致线程错误

ios - 使用 Gloss 框架的可解码、可编码、光泽一致性问题

objective-c - 从自定义 uitableviewcell 中的按钮点击委托(delegate)

iphone - 如何在瀑布 View 中自动设置图像宽度和高度?

iphone - 不会调用 canMoveRowAtIndexPath - 但会调用 canEditRowAtIndexPath

ios - 在 iOS 中比较两个音频文件

ios - 如何从完成处理程序 iOS Swift 3 获取值

ios - 当 ViewController 解析网站时,UITableView header 中的 iAd 会重新加载

ios - 在 UITableViewCell 中使用多行向 2 个标签添加约束