简体   繁体   中英

Swift UIView Border adjusts after UITableView scrolling

I have a problem with my UITableView sections (and their height, I guess). Within a section header, I have a view (named cornerRadiusView) within which there are few labels. These labels have dynamic content (fetched from a REST service). So whenever a UILabel height is increased, I am increasing the height of the cornerRadiusView to properly accommodate the content.

The problem is, all this works as expected only when I scroll my tableView. Till then, the heights are improper.

Here I am posting GIF to show what's going on.

I can give more details and code as needed. Could someone please look at where there is a problem?

You can use below functions

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

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }

And reload table view in below method

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
      tableview.reloadData()
    }

And if you are maintaining dynamic height then manage those height in cell

 override func layoutSubviews()
 {
 }

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