简体   繁体   English

滚动UITableView后,Swift UIView Border进行调整

[英]Swift UIView Border adjusts after UITableView scrolling

I have a problem with my UITableView sections (and their height, I guess). 我的UITableView部分(及其高度,我想)有问题。 Within a section header, I have a view (named cornerRadiusView) within which there are few labels. 在节标题中,我有一个视图(名为cornerRadiusView),其中没有几个标签。 These labels have dynamic content (fetched from a REST service). 这些标签具有动态内容(从REST服务获取)。 So whenever a UILabel height is increased, I am increasing the height of the cornerRadiusView to properly accommodate the content. 因此,每当UILabel高度增加时,我都会增加cornerRadiusView的高度以正确容纳内容。

The problem is, all this works as expected only when I scroll my tableView. 问题是,只有当我滚动tableView时,所有这些工作才能按预期进行。 Till then, the heights are improper. 到那时,这些高度是不合适的。

Here I am posting GIF to show what's going on. 在这里,我发布了GIF以显示正在发生的事情。

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()
 {
 }

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

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