简体   繁体   中英

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. 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

在此处输入图片说明

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. Moving those may be all you need to do to correct the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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