简体   繁体   English

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

[英]UITableView not scrolling properly to bottom until a cell is clicked

I have a UITable view which has a view at the top and then some cells below it. 我有一个UITable视图,该视图在顶部有一个视图,在下面有一些单元格。 this sort of hierarchy 这种等级制度

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

now i have my cells as a dynamic height so they expand according to the label height, now this works fine when having a single line label, but when i have the label set to 0 (multi line) my tableview bounces back to the top when trying to scroll, but when you click on one of those cells after this it scrolls as its meant to, to the bottom cells 现在我将单元格设置为动态高度,因此它们会根据标签高度进行扩展,现在在使用单行标签时此方法可以正常工作,但是当我将标签设置为0(多行)时,tableview会弹回顶部尝试滚动,但是在此之后单击这些单元格之一时,它会按原意滚动到底部单元格

在此处输入图片说明

Im relatively new to swift so please bare that in mind with the answers 我相对较新,所以请在回答时将其基本记住

Thanks in advance 提前致谢

This is the code for populating the cells 这是填充单元格的代码

   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)

    }

These two lines: 这两行:

   myTableView.estimatedRowHeight = 50
   myTableView.rowHeight = UITableViewAutomaticDimension

belong in viewDidLoad() , not where you have them. 属于viewDidLoad() ,而不是它们所在的位置。 Moving those may be all you need to do to correct the problem. 解决这些问题可能就是您要做的所有事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM