Reputation: 182
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
Upvotes: 17
Views: 23941
Reputation: 1460
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.
Upvotes: 18