【发布时间】:2017-07-18 14:02:49
【问题描述】:
我有一个UITableViewcustom 单元格。它有一个UIView和一个UIButton
我想在我的`cellForRowAtIndex.xml 中以编程方式更改此视图高度约束和按钮的顶部约束。所以在这里面我是这样做的。
if(myintime2 == "00:00" && myoutTime2 == "00:00" )
{
cell.btnIntime2.setTitle(myintime2, for: .normal)
cell.btnOutTime2.setTitle(myoutTime2, for: .normal)
cell.btnOutTime2.isHidden=true
cell.btnIntime2.isHidden=true
cell.customViewHeightConstraint.constant = 111
cell.customBtnIn1Top.constant = 111/2
}
else if (myintime2 == "N/A" && myoutTime2 == "N/A")
{
cell.btnIntime2.setTitle(myintime2, for: .normal)
cell.btnOutTime2.setTitle(myoutTime2, for: .normal)
cell.btnOutTime2.isHidden=true
cell.btnIntime2.isHidden=true
cell.customViewHeightConstraint.constant = 111
cell.customBtnIn1Top.constant = 111/2
}
else
{
cell.btnIntime2.setTitle(myintime2, for: .normal)
cell.btnOutTime2.setTitle(myoutTime2, for: .normal)
cell.customViewHeightConstraint.constant = 222
cell.customBtnIn1Top.constant = 10
cell.btnOutTime2.isHidden=false
cell.btnIntime2.isHidden=false
}
但是有些单元格的高度不对,请帮帮我
【问题讨论】:
-
“某些单元格的高度错误”到底是什么意思?预期的结果是什么,会发生什么?
-
@mag_zbc 我必须检查 2 个条件。如果我的 in time2 可用,我想增加单元格的高度并增加按钮的顶部约束值。但是当我的条件不满足时,细胞越来越多,顶部也越来越大。
-
@mag_zbc 但并非适用于所有单元格,这只发生在少数单元格中。随机
-
@mag_zbc 而且当我滚动表格视图时,一些正确的单元格也会得到错误的大小
-
在重新创建高度之前尝试清除约束
标签: ios uitableview swift3 nslayoutconstraint custom-cell