Hiding a preview in UIStackview in ios

To hide a view in UIStackView , is it better to set isHidden to true or use removeArrangedSubview and instead remove the view from the parent Stackview ?

I use Stackview to organize my UIElements in a tableView cell. I currently have a parent StackView and a child stackview located inside. The children's performance should be displayed or hidden depending on the state. I set the isHidden property of the child view to true when the condition becomes true.

When I browse and new cells appear, they become visible. I get the following messages in the console. The application does not crash.

NSLayoutConstraint: 0x600000093470 'UISV-canvas-connection' UIStackView: 0x7fd4527201b0.top == UILabel: 0x7fd452720370 "Disconnecting - rest and sleep ...". top (active)

Set a symbolic breakpoint on UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. Methods in the UIConstraintBasedLayoutDebugging category in UIView, listed in <UIKit/UIView.h> may also be useful. [LayoutConstraints] Unable to satisfy constraints at the same time. Probably at least one of the restrictions on the following list is one you don't want.
Try the following:

  • look at each restriction and try to find out what you are not expecting;
  • find the code that added the unwanted restriction or restrictions and correct it. ("," ",", "", "," "," ")

Will try to recover, violating the restriction

+7
ios swift swift3 uistackview
source share
1 answer

To answer your first question, if you do not need to display the subview, it would be most logical to remove it using removeArrangedSubview(UIView) . As you may know, the stack view will automatically update its layout when views are added, deleted, inserted or hidden / hidden.

The warning you receive in the console about restrictions may or may not be related to what you have now implemented for the subtitle. Did you mention this because you think it could be related?

Hope this helps.

+8
source share

All Articles