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

安稳与你 提交于 2020-01-04 05:42:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/48223478/how-to-manage-the-items-in-the-storyboard-to-add-the-possibility-to-expand-colla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!