0

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?

Lohith Korupolu
  • 1,066
  • 1
  • 18
  • 52
  • Please post your code showing how you set height for cells and sections. Please also post your code showing what is triggered when you scroll it. – Fangming Jun 28 '17 at 09:20
  • I have my question elaborated in https://stackoverflow.com/questions/44718598/swift-tableview-row-height-updates-only-after-scrolling-or-toggle-expand-colla - there is also a bounty for it :) – Lohith Korupolu Jun 28 '17 at 09:28

1 Answers1

0

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()
 {
 }
Vibha Singh
  • 623
  • 4
  • 9
  • thanks! I didn't understand the last method though. Leaving that aside, I added the other two mentioned in your answer and now it looks like this - http://g.recordit.co/pigXE77P2R.gif Would something be interesting to look at my code? I have the question elaborated in https://stackoverflow.com/questions/44718598/swift-tableview-row-height-updates-only-after-scrolling-or-toggle-expand-colla – Lohith Korupolu Jun 28 '17 at 07:34