gpt4 book ai didi

swift - UITableViewAutomaticDimension-10.0

转载 作者:行者123 更新时间:2023-11-30 12:39:32 26 4
gpt4 key购买 nike

我试图将最后一个tableView行的高度设置为与其他行不同。我不想创建一个新的单元格等,而是想从该单元格的高度“剪切”10px。由于我设置了高度的自动尺寸,因此无法使用恒定值。

它是这样的:

tableView.estimatedRowHeight = 54.0
return UITableViewAutomaticDimension

我想要这样的东西,但这不起作用:

if isLastLineBla {
tableView.estimatedRowHeight = 44.0
return UITableViewAutomaticDimension-10.0
} else { ...

最佳答案

我希望您拥有 tableViewdataSource 并在 numberOfRowsAt 方法中返回 dataSource.count

现在实现 heightForRowAt 方法以返回正确的值,如下所示:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if lastRow {
return 44
}else{
return UITableViewAutomaticDimension
}
}

并且不要在每个地方都设置 tableView.estimatedRowHeight = 44.0,唯一需要设置的地方是在 viewDidLoad 方法中。

关于swift - UITableViewAutomaticDimension-10.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396225/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com