11

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.

Justin Pfenning
  • 433
  • 1
  • 5
  • 18
  • I cannot reproduce your problem on the basis of what you've shared with us. If we cannot reproduce your problem, it's hard to solve the problem. Maybe you can create a [MCVE](http://stackoverflow.com/help/mcve), namely start with blank project and then add a table view & cell that reproduces the warning you describe. Then you can share that project with us. – Rob Dec 02 '16 at 14:49
  • @Rob - I updated it to include the MCVE – Justin Pfenning Dec 02 '16 at 15:19
  • Are you getting compile-time warnings or run-time warnings? I'm getting no compile time warnings in Xcode 8.1 (8B62). When I tried to run this, obviously you didn't have a view controller or cell class included, but when I added those, it worked fine, though to avoid runtime warnings, I had put the following lines in `viewDidLoad` of the `UITableViewController` subclass: `self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 222;`. – Rob Dec 02 '16 at 15:53
  • @Rob - I have the same version of xcode. They result in compile time warnings. Everything works fine at run time. Here is a [screenshot](http://justinpfenning.com/ScreenShot.png) of what I am seeing. – Justin Pfenning Dec 02 '16 at 19:53
  • Let's see if anyone else can reproduce these warnings, because I'm not seeing them. I might suggest locating the derived data folder, quitting Xcode, purging that folder and restarting Xcode, just to make sure. But if you're seeing this in your main project and your MCVE problem, I'm not optimistic that this will solve it. Maybe a reboot, too. – Rob Dec 02 '16 at 19:58
  • At Xcode 8.1: No warning! – Irfan Dec 03 '16 at 11:02
  • Thank you all for your help and assistance. I fixed this and answered my own question below, but I really appreciate everyone here taking the time to test it out. – Justin Pfenning Dec 12 '16 at 14:32

2 Answers2

11

The way I solved this was to either:

  1. Remove the bottom constraint on the main stack view to the bottom of the SuperView so only 3 sides were pinned.

or

  1. Adjust the row height of the table cell. Although it is a dynamic height cell based on label/button heights, I guess it still needs to be the "correct" height in interface builder?

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Justin Pfenning
  • 433
  • 1
  • 5
  • 18
5

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.

Ravi Gupta
  • 97
  • 2
  • 5
  • 1
    Thanks! I found that you can just give the height constraint with a priority of 1. No need to remove it at runtime. That seems to do it as well. – Andy Weinstein Oct 01 '20 at 17:50