Calculation of content View table size with dynamic cell enlargement

I am trying to calculate the height of the content size of a tableView with dynamically growing cells. For this, I write code as -

override func viewDidLoad() { super.viewDidLoad() self.tableView.estimatedRowHeight = 150 self.tableView.rowHeight = UITableViewAutomaticDimension } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! MostLikedTVCscnd cell.image.image = imageArr[indexPath.row] as? UIImage cell.aboutLbl.text = labelArr[indexPath.row] as? String let contentSizeHeight = tableView.contentSize.height//But here I am not getting the proper height return cell } 

I checked the answer in the question for calculating the size of the contents of a View table - stack overflow site/questions/150932 / ... that reads

Note for those for whom this does not work - tableView: measuredHeightForRowAtIndexPath messes with contentSize, so you might be lucky just by deleting its implementation. - weienw

So are there any means in which I can get the right size of the content, despite the dynamic size of the cell?

+5
source share
1 answer

You can use Key Value Observation (KVO) to receive notifications each time the contents of a table are resized. This may or may not work for what you are trying to do. It’s just not clear to me what you want to get, but I don’t think it would be nice to try to use this in cellForRowAtIndexPath.

0
source

Source: https://habr.com/ru/post/1244799/


All Articles