如何管理故事板中的项目以添加展开/折叠 tableView 单元格的可能性 [英] How to manage the items in the storyboard to add the possibility to expand/collapse the cell of the tableView

查看:33
本文介绍了如何管理故事板中的项目以添加展开/折叠 tableView 单元格的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 tableView 中创建通过单击展开和折叠各种单元格的能力,而不考虑代码,我必须如何设置故事板中的元素和约束?从某种意义上说,在我的单元格的内容视图中,我应该添加多少个 UIView,假设我想在展开单元格时将单元格的大小加倍,这个 UIView 我必须在相同大小的顶部添加一个?约束呢?我已经尝试过看一些教程,但他们不太清楚.

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.

推荐答案

使用 UIStackView 来包含单元格的内容,并将单元格设计为展开的.然后只需为那些应该折叠的 stackView 排列的子视图设置 view.isHidden = true.然后,您可以通过在适当的子视图上将 isHidden 设置为 true 或 false 来在展开和折叠单元格之间切换(您将在 @IBAction 中作为对单击按钮的反应),或类似的东西).但是您仍然需要在代码中注意其他一些部分才能使其正常工作,请参阅我在 SO 问题中的回答.您可以在此SO Question中找到您想要的编程示例,如果您知道的话阅读代码,您就会知道如何在故事板中进行操作 - 原理是相同的,您只需要在故事板中设置约束和内容即可.

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.

这篇关于如何管理故事板中的项目以添加展开/折叠 tableView 单元格的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆