Ios 在Swift中将UITableViewCell的大小设置为HeightForRowAt func后,如何调整UITableViewCell的大小?
我希望最新的TableView单元格与TableView一样大,但我希望每次创建新单元格时,旧单元格都能恢复到正常大小 我已经尝试过了,在HeightForRowAt函数中这样做,但是每个单元格都保持在TableView大小上Ios 在Swift中将UITableViewCell的大小设置为HeightForRowAt func后,如何调整UITableViewCell的大小?,ios,swift,uitableview,Ios,Swift,Uitableview,我希望最新的TableView单元格与TableView一样大,但我希望每次创建新单元格时,旧单元格都能恢复到正常大小 我已经尝试过了,在HeightForRowAt函数中这样做,但是每个单元格都保持在TableView大小上 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { var cellHeight: CGFloat = CGFloat()
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var cellHeight: CGFloat = CGFloat()
for cell in tableView.visibleCells {
cellHeight = cell.bounds.height
}
let TableHeight = tableView.frame.height
if indexPath.row == arr.count - 1 {
return TableHeight
}else{
return cellHeight
}
}
有没有办法在创建单元格后调整其大小,或者有任何其他解决方案来解决我的问题
提前谢谢试着在正常单元格高度中设置常量
if indexPath.row == arr.count - 1 {
return TableHeight
}else{
return 40 // or whatever you want
}
如果你问自己为什么?
第一次单元格高度将为零,最后一次单元格高度将为桌面高度
然后每次调用heightForRowAt方法时,您的单元格高度将为=TableHeight,最后一个高度也将为TableHeight
因为for循环将从可见单元格返回最后一个单元格高度,并且您有一个可见单元格
“其他单元格不可见高度=零”
,所以它将是表高,谢谢,这是有效的。但我有动态单元格高度,带有自动布局,因此如果单元格大于正常单元格高度,它将被切断。