fisherM
fisherM

Reputation: 177

How to manage the items in the storyboard to add the possibility to expand/collapse the cell of the tableView

I'm trying to create in my tableView the ability to expand and collapse the various cells with a click, not considering the code, how I have to set the elements and constraints in the storyboard? In the sense, in the content view of my cell how many UIView should I add, assuming that I want to double the size of the cell when I expand it, this UIView I have to add one on top of the same size? The constraints instead? I already tried to give a look at some tutorials but they were not too clear about it.

Upvotes: 2

Views: 227

Answers (1)

Milan Nosáľ
Milan Nosáľ

Reputation: 19757

Use UIStackView to contain your content of the cell, and design the cell as expanded. Then just set view.isHidden = true for those stackView's arranged subviews that should be collapsed. Then you can switch between expanding and collapsing the cell by setting isHidden to true or false on appropriate subviews (that you will do in an @IBAction as a reaction to clicking a button, or something similar). But there will still be some other parts that you will have to take care in the code to make it work, see my answer in SO Question. A programmatical example of what you want you will find in this SO Question, if you know to read the code you'll know how to do it in storyboards - the principle is the same, you just need to setup constraints and contents in storyboards.

Upvotes: 2

Related Questions