Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell dynamic height + hidden elements take up space in Swift?

This is the scenario: I have a Table in which there are Cells with dynamic height. In each cell I have a label and a switch. When I run the App only these two can be seen but then I set the switch to true then a (hidden?) textview appears under these two elements making the height of the cell bigger.

How can I do this? Because when I try hidden elements take up place as well.

This is what I want: enter image description here

Reality: enter image description here

How can I do this? I tried using the new Stack View which can handle it fine, BUT NOT in a table cell....

How can I solve this?

like image 678
nethuszar Avatar asked Jul 18 '16 21:07

nethuszar


1 Answers

I solved it mixing this answer: Dynamic Height Issue for UITableView Cells (Swift) for the dynamic height and then for the views that show or not I added a height constraint to the view and then on cellForRowAtIndexPath just set the constant of the constraint to 0 if you need to hide it or to your height if you show it.

Hope it helps!

like image 183
agfa555 Avatar answered Nov 07 '22 02:11

agfa555