1

Confused on this one...

I have a stackview in a tableview cell. The stackview (Center, Equal Spacing) has two sub stackviews, Left stackview (Fill, Fill) has a UIButton (infoButton) and UILabel (Description) Right stackview (Fill, Fill) has just UILabel

When I set infoButton.isHidden = true, Description is nowhere to be seen on iOS 10.2. On iOS 11.1 it works as expected.

Thanks for taking a look!

Image: iOS 11.1 on left, iOS 10.2 on right.

Additional Info:

if (input.Help == ""){
    aCell.infoButton.isHidden = true
} else {
    aCell.infoButton.isHidden = false
    aCell.infoButton.tag = i
    aCell.infoButton.isUserInteractionEnabled = true
    aCell.infoButton.addGestureRecognizer(tap)
}

Solved: I changed the Stack View (that contains the button and label together) to Alignment 'Center' instead of 'Fill'. The Stackview height had been changing to 0 as observed in the View Debugger (thank you Matt for pointing me to the debugger!)

iOS 11.1 on left, 10.2 on right

Evan Winograd
  • 101
  • 1
  • 9
  • 3
    Certainly the difference between systems is interesting but nothing can be said from just looking at some app screen shots. Can you clarify a bit? Unclear what's what in the screen shots. We're going to need to a lot more than a screen shot anyway: to reproduce, the entire hierarchy of stack views, settings, and constraints is needed. See https://stackoverflow.com/help/mcve — Also, you do know about the View Debugger, right? It will tell you where the Description went and why. For example, maybe the stack view _itself_ is what's disappearing (because there is something wrong with its layout). – matt Dec 01 '17 at 16:09
  • I added some code above and didn't know about the view debugger - I'll check that out now, thanks! – Evan Winograd Dec 01 '17 at 19:23
  • View debugger worked like a charm! Looks like the stack view shrunk to height 0 when I set the button to hidden. I changed Alignment to Center instead of Full and that did the trick. Thanks for the help! – Evan Winograd Dec 01 '17 at 19:29
  • 2
    Hoorah! Thanks for reporting back. (And I must also pat myself on the back for guessing correctly that it was the stack view itself that was vanishing.) In my estimation, this question could be useful to others, so please feel free to answer your own question, and in 48 hours you can even accept your own answer (all perfectly legal here on Stack Overflow). – matt Dec 01 '17 at 19:33
  • Thanks, matt! I'll mark it as the answer when it lets me. – Evan Winograd Dec 03 '17 at 02:53

2 Answers2

1

Changed the Stack View (that contains the button and label together) to Alignment 'Center' instead of 'Fill'.

The Stackview height had been changing to 0 as observed in the View Debugger (thank you Matt for pointing me to the debugger!) when one subview of the stack was set to hidden.

Evan Winograd
  • 101
  • 1
  • 9
  • 1
    For me it was some "same width/height" constraints which I had to remove from buttons shown in the stackview – decades Nov 30 '18 at 11:59
0

I had a similar issue placing a Label and Text Field inside stack view containing another Label as the title. Wanted to hide/show Text Field and Label for editing purposes (eg: First Name Label and First Name Text Field. If editing would show only the Text Field, otherwise, show only the Label).

Title:      First Name (always visible)
Label:      John (hidden when editing)
Text Field: John (hidden when not editing)

My problem: When showing back the Label it was disappearing along with the title Label.

My solution: Embedding into a stack view the Name Label and Text Field

Hope this helps :)

LeCalore
  • 80
  • 3
  • 8