I have a ScrollView
that takes up the entire device screen.
Inside of this ScrollView
there is a View
that hold 3 Label
s, underneath a TableView
, and then at last underneath, a Label
.
Now, the TableView
has an unknown amount of items being injected into it and I do not want it to scroll, so I have attached its height as a NSLayoutContraint
that is dynamically sized and reloaded once the items have been parsed.
This is how the table is being resized after the data comes in:
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var tableHeight: NSLayoutConstraint!
var array = [String]()
let import = self.items!["people"] as? String
array = import!.componentsSeparatedByString(",")
let height = CGFloat(self.array.count * 50)
self.tableHeight.constant = height
self.tableView.reloadData()
That is all well and dandy, but the problem comes with the AutoLayout and I keep getting errors. I have tried the following things:
- Setting the inner
View
layout to be pinned against theScrollView
. First, Xcode is saying"Scrollable content size ambiguous for ScrollView"
and when running it, there are no console errors but theView
expands horizontally past theScrollView
viewport and theLabel
underneath the dynamic content shows.
Number 2 prescribed by: UIScrollView Scrollable Content Size Ambiguity
- Setting the inner
View
to be centered horizontally and centered vertically with theScrollView.
This removed the ambiguous content size error (Yay!), and corrected theView
from running past theScrollView
viewport (Yay!), but theLabel
underneath the dynamically-sizedTableView
is not hidden (assuming its under theTableView
) BUT I am now understandably getting theUnable to simultaneously satisfy constraints.
error in the console.
Those are the two outcomes I have come to but I am now stuck. I have checked the steps about ScrollViews in the Apple Documentation and followed it exactly to be sure, but I think I am having this issue because of the dynamically-sized TableView or some AutoLayout mistake I am making.
Can anyone help? Thank you!