1

i want to set height constraint to my UITableView so i can stretch it. The problem is that im not getting accurate reading with tableView.contentSize.height. My table has 10 rows when each is 40px height. tableView.contentSize.height reads as 388 while 10 * 40 (which is the actual height is 400)

what am i missing here? thanks

orthehelper
  • 4,009
  • 10
  • 40
  • 67
  • How is your table view setup? The table view's `contentSize` will be correct once the table view has been displayed assuming you are not using any estimated row heights. – rmaddy Feb 25 '18 at 16:26
  • @rmaddy it is using estimated row height. but im calling reloadData before which is synchronous – orthehelper Feb 26 '18 at 05:30

1 Answers1

0

It seems that the contentSize (as being a property of UIScrollView, which UITableView inherits from and uses) does not have its final value until later, probably because table cells are loaded dynamically. Instead you can calculate the correct height yourself.

Here is one way of doing that

LGP
  • 4,135
  • 1
  • 22
  • 34