Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the subview in UIStackview in ios

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:

  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. ( "", "", "", "", "", "", "" )

Will attempt to recover by breaking constraint

like image 383
jay Avatar asked Jan 16 '17 23:01

jay


People also ask

How do I hide a stack view?

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.

How do I hide a view in IOS Swift?

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.

What is Uistackview?

A streamlined interface for laying out a collection of views in either a column or a row.


1 Answers

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.

like image 117
Jim Avatar answered Sep 19 '22 06:09

Jim