gpt4 book ai didi

ios - 在单击单元格之前,UITableView 无法正确滚动到底部

转载 作者:行者123 更新时间:2023-11-28 12:15:18 26 4
gpt4 key购买 nike

我有一个 UITable View ,它在顶部有一个 View ,然后在它下面有一些单元格。这种层次结构

<tableview>
<view></view>
<cell></cell>
<cell></cell>
<cell></cell>
</tableview>

现在我将我的单元格设置为动态高度,因此它们会根据标签高度扩展,现在这在具有单行标签时工作正常,但是当我将标签设置为 0(多行)时,我的 tableview 弹回尝试滚动时位于顶部,但是当您在此之后单击其中一个单元格时,它会按预期滚动到底部单元格

enter image description here

我对 swift 比较陌生,所以请在回答时记住这一点

提前致谢

这是填充单元格的代码

   public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{

myTableView.estimatedRowHeight = 50
myTableView.rowHeight = UITableViewAutomaticDimension

let cell = Bundle.main.loadNibNamed("ProfilerTableViewCell", owner: self, options: nil)?.first as! ProfilerTableViewCell

cell.cellDescription.text = RatingsDataSet[n].descriptions[indexPath.row]
if RatingsDataSet[n].valuesdata[indexPath.row][0] != "0" {
cell.valueLabel.setTitle(RatingsDataSet[n].valuesdata[indexPath.row][0], for: .normal)
}else{

cell.valueLabel.setTitle("Not Set", for: .normal)
cell.valueLabel.backgroundColor = UIColor.lightGray

}

return(cell)

}

最佳答案

这两行:

   myTableView.estimatedRowHeight = 50
myTableView.rowHeight = UITableViewAutomaticDimension

属于viewDidLoad(),而不是你拥有它们的地方。您可能只需移动它们即可解决问题。

关于ios - 在单击单元格之前,UITableView 无法正确滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46829256/

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