In order to hide a subview in UIStackView
is it better to set the isHidden
to true or to use removeArrangedSubview
and remove the subview from the parent Stackview
instead ?
I am using a Stackview to arrange my UIElements in the tableView cell.
I currently have a parent StackView and a childStackview arranged inside. The child view needs to be shown or hidden based on a condition. I am setting the isHidden
property of the child view to true when the condition turns true.
When I scroll and new cells come become visible I get the following messages in the console. The app does not crash.
NSLayoutConstraint:0x600000093470 'UISV-canvas-connection' UIStackView:0x7fd4527201b0.top == UILabel:0x7fd452720370'Day Off - Rest and Sleep ...'.top (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.
[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:
Will attempt to recover by breaking constraint
In order to hide a view within a stack view, set the contained view's hidden property to true , and the stack view handles the rest. This is how you'll fix the spacing under the WEATHER label when the user hides the text below it.
Use an opacity modifier when you don't want other content to shift around as the view appears or disappears. This modifier is similar to the hidden property in UIKit.
A streamlined interface for laying out a collection of views in either a column or a row.
To answer your first question, if you don't have a need to unhide the subview, the most logical thing to do would be to remove it using removeArrangedSubview(UIView)
. As you might know, the stack view will automagically update its layout whenever views are added, removed, inserted, or hidden/unhidden.
The warning you're getting in the console about the constraints may or may not be related to whatever you've implemented for the subview right now. Did you mention it because you think it might be related?
Hope that helps.
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