When is preferredContentSize respected?
Now I had the same problem another time. If I put my table height calculation into viewWillAppear
than it works:
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
TableView.LayoutIfNeeded ();
this.PreferredContentSize = new SizeF (320f, TableView.ContentSize.Height);
}
The code is in C# but you can easily convert it to Objective-C or Swift.
I converted testing’s code to Swift 2.0.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
tableView.layoutIfNeeded()
preferredContentSize.height = tableView.contentSize.height
}