I have a UITableViewCell that has an embedded UIStackView in it. Everything works and looks fine on the phone and iPad. However, I get a lot of weird errors in the StoryBoard and I don't know if I can ignore them or not. Typically, I hate ignoring warnings. But is it OK in this case? My Table Cell is set up as follows:
UITableViewCell
- Content View
-- View (named outerView)
--- View (named dateView for top banner color)
--- UIStackView (vertical, named mainStackView, pinned to neighbors)
---- UIButton (A)
---- UIView (B)
---- UIStackView (C, horizontal)
---- UIStackView (D, horizontal)
---- UILabel (E)
---- UIButton (F)
Everything under the mainStackView (letters A-F) are all showing an error in StoryBoard that they "Need constraint for: Y position or height". However, per the Apple documentation it says they will handle all the constraints and vertical alignment if the UIStackView is vertical orientation. Like I said, it works fine and the arrangedSubviews can be collapsed/hidden and there are no other warnings. I just don't like shipping out code riddled with warnings. What can I do to fix this, or is it a known issue?
UPDATE: Here is the MCVE as requested by the comment below. Click here and unzip the folder to get the bare bones project that will only work in Interface Builder.
fill distribution creates constraints attaching the top of the first arranged subview to the top of the stack view, and the bottom of the last arranged subview to the bottom of the stack view. It also creates a constraint between the top/bottom of adjacent subviews with the spacing of the stack view.
To use a stack view, open the Storyboard you wish to edit. Drag either a Horizontal Stack View or a Vertical Stack View out from the Object library, and position the stack view where desired. Next, drag out the stack's content, dropping the view or control into the stack.
Once selected, click the Embed In button in the Auto Layout toolbar at the bottom-right of the storyboard canvas. A menu with available embed options will appear. Choose Stack View: Xcode will embed the buttons in a new stack view for you.
I also had similar problem with the vertical stack view. The way i solved it by giving height constraint to any subview(in my case horizontal stack view) and removing it at build time. I also tried this on your MCVE and it worked.
Note: This is certainly a hack but it resolved the problem.
The way I solved this was to either:
or
I had to use option 2 because if I did option 1, my table cell disappeared as it did not know how the height to use for the cell.
Also worth reiterating that the code as before still worked fine, it just had compilation warnings. I have no idea why nobody else could see them despite being on the same level Xcode. Now off to try and get my 3 days back and work on my OCD about warnings in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With