【问题标题】:can't change cell hight based on background color swift无法根据背景颜色快速更改单元格高度
【发布时间】:2016-11-28 21:47:23
【问题描述】:

我正在尝试制作一个根据背景颜色更改单元格高度的应用。我想拥有它,这样如果它们的背景颜色是青色或橙色,单元格会更小,但我似乎找不到正确的方法。我有更改高度的代码,但我不知道要使用的正确参数。

override func tableView(tableView: UITableView,
               heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == 1 {//should be if cell.backgroundcolor or something
        return 100 //noncolored cells
    } else {
        return 20 // colored cells
    }
}

【问题讨论】:

  • 你能解决这个问题吗?

标签: swift uitableview cell background-color


【解决方案1】:

您应该使用对象的数组来确定哪个对象应该具有哪个高度。至少创建将保留该信息的布尔值数组。在这里,这是非常值得怀疑的,因为细胞是可重复使用的。

我建议您使用与cellForRowAtIndexPath 相同的条件来设置单元格背景。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2011-04-03
    • 2022-01-20
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多