1) Add a restriction link to your class:
var heightC: NSLayoutConstraint!
2) Disable scrolling and add height limit:
tableView.scrollEnabled = false heightC = tableView.autoSetDimension(.Height, toSize: 20) // using PureLayout library
3) override viewDidLayoutSubviews of your controller:
override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() heightC.constant = tableView.contentSize.height }
and set the "const" attribute of the height limit for the height of the table contents.
4) when updating data (for example, when the number of elements changes from 0 to more), it simply forcibly displays the representation of the main controller in the layout:
view.setNeedsLayout()
Leszek Ε»arna
source share