0

I'd like to have a small grid with 3 rows and 2 columns. The first column has a number 1..3, the second text. Each row is created with two UILabel fields in a horizontal StackView, all these are themselves contained in a vertical StackView. This outer StackView has leading, trailing, top and bottom constraints to its super view to keep it in place.

This is the view controller scene from Xcode 9

enter image description here

The outer StackView 'Steps' has:

Axis = Vertical
Alignment = Fill
Distribution = Fill Proportionally

Each of the row StackViews has:

Axis = Horizontal
Alignment = Center
Distribution = Fill Proportionally

If've got two problems: a) XCode's StoryBoard does not show anything i.e., I see a big white, empty ViewController. Clicking the components in the inspector I can see the outlines of where 'stuff' should show but, I see none of the text, nana. b) When I run the 'app' it actually shows the text where it should be, however, i get the following in the debugger output:

2018-03-22 13:41:33.423864-0700 stackview_test[35635:4781389] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60c000089d80 'fittingSizeHTarget' UIStackView:0x7feb69614b00.width == 0   (active)>",
    "<NSLayoutConstraint:0x60c00008f050 'UISV-canvas-connection' UIStackView:0x7feb69614b00.leading == UILabel:0x7feb69614d00'2'.leading   (active)>",
    "<NSLayoutConstraint:0x60c00008f190 'UISV-canvas-connection' H:[UILabel:0x7feb69614fe0'Lorem ipsum dolor sit ame...']-(0)-|   (active, names: '|':UIStackView:0x7feb69614b00 )>",
    "<NSLayoutConstraint:0x60c00008f910 'UISV-spacing' H:[UILabel:0x7feb69614d00'2']-(20)-[UILabel:0x7feb69614fe0'Lorem ipsum dolor sit ame...']   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60c00008f910 'UISV-spacing' H:[UILabel:0x7feb69614d00'2']-(20)-[UILabel:0x7feb69614fe0'Lorem ipsum dolor sit ame...']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-03-22 13:41:33.428202-0700 stackview_test[35635:4781389] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60800008da20 'fittingSizeHTarget' UIStackView:0x7feb696156e0.width == 0   (active)>",
    "<NSLayoutConstraint:0x60c0000903b0 'UISV-canvas-connection' UIStackView:0x7feb696156e0.leading == UILabel:0x7feb69615de0'3'.leading   (active)>",
    "<NSLayoutConstraint:0x60c000090450 'UISV-canvas-connection' H:[UILabel:0x7feb696160c0'At vero eos et accusamus ...']-(0)-|   (active, names: '|':UIStackView:0x7feb696156e0 )>",
    "<NSLayoutConstraint:0x60c000090770 'UISV-spacing' H:[UILabel:0x7feb69615de0'3']-(20)-[UILabel:0x7feb696160c0'At vero eos et accusamus ...']   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60c000090770 'UISV-spacing' H:[UILabel:0x7feb69615de0'3']-(20)-[UILabel:0x7feb696160c0'At vero eos et accusamus ...']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Any idea what is going on? I'd sure appreciate your insights.

Yohst
  • 1,671
  • 18
  • 37
  • All your issues with label constraints can be resolved by putting your label inside a UIView.. So the hierarchy will be StackView -> UIView -> UILabel. I have always suffered the wrath of a uilabel inside a stack view.. the concepts like hugging priority, label width/font adjustment need to be clear to work with stackview/label seamlessly.. but puttting a label within a UIView is a quick workaround – Akshansh Thakur Mar 22 '18 at 21:06
  • @AkshanshThakur are you sure hugging priority and content compression ratios can be solved by putting them in UIVIew? I don't think so... – Naresh Mar 22 '18 at 21:10
  • @Naresh When two lables are stacked horizontally, they work a little differently. i find xcode a little buggy when dealing with such cases.. for example: https://stackoverflow.com/questions/46603285/xcode-stackview-empty-labels-freaks-out-in-stack-view?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Akshansh Thakur Mar 22 '18 at 21:12
  • This would work a lot better as a table view and no stack views. Or even as 6 labels and no stack views. – matt Mar 22 '18 at 21:13
  • @matt I know, this is just an extraction of the 'real mess' I have with a much more complicated ViewController. I've gotta understand why this fails, not alternatives. – Yohst Mar 22 '18 at 21:15
  • @Yohst You don't see anything on the storyboard because xcode might be slow in rendering... it also happens when you have a lot of ibinspectable properties... dont't worry about that – Naresh Mar 22 '18 at 21:16
  • @Yohst So are you telling us that Interface Builder doesn't warn in the canvas that there are structural issues with your layout, even though you will get structural issues with your layout at runtime? There is no little yellow or red alert icon? – matt Mar 22 '18 at 21:17
  • @AkshanshThakur I played around with embedding the UILabels in UIViews but besides just making it more complex, don't I just end up setting hard values (width/height) which the StackView should actually manage for me? If the text is to be localized, it needs to fully autolayout. – Yohst Mar 22 '18 at 21:17
  • @Naresh; XCode has been 'sitting there' for many a minute, it should have rendered it by now. And I do 'worry about it' because not seeing what the result looks like makes it rather difficult to design. As I said to matt above, this is just an extracting of a much more complicated view. – Yohst Mar 22 '18 at 21:19
  • One more thing I discovered is that the UILabels that hold a lot of text are set to have 2 or more lines. Once I set them to 1 line, Storyboard behavior appears to be a bit more agreeable; i.e., I can see it rendering. Sooh, am I just up against Xcode (typical) crappiness again? – Yohst Mar 22 '18 at 21:50
  • @Yohst You’ll notice that the log only references the 2nd and 3rd stack views Loren ipsum... my hunch is that you performed a copy paste and it’s got underlying constraints. Delete them and manually create your labels with multiple lines of text and see how that goes. – Jake Mar 23 '18 at 01:16
  • @Jake; sharp eyes, I know I had no constraints attached in the first place but went through your proposed steps anyway. No change, issue persists. – Yohst Mar 23 '18 at 21:02

0 Answers0