UITableViewCell 点击展开 [英] UITableViewCell expand on click
问题描述
假设我们有一个自定义的 UITableViewCell
Lets say we have a custom UITableViewCell
所以每当我点击单元格上的自定义按钮时..它应该扩展到一定程度(你可以说40个高度......),当我再次点击同一个自定义按钮时,它应该折叠到以前的高度.
So whenever I click custom button on cell.. it should expand to the some extent (you can say 40 height more...) and when i click again to the same custom button it should collapse to the previous height.
开发人员请指导我..我怎样才能完成这个任务
Developer's please guide me.. how can I achieve this task
推荐答案
实现 heightForRowAtIndexPath 以计算正确的高度.然后在按钮的代码中,使用 beginUpdates 和 endUpdates 强制表格重新计算每个单元格的高度:
Implement heightForRowAtIndexPath to calculate the right height. Then in the code for your button, force the table to reevaluate each cell's height with beginUpdates plus endUpdates:
[self.tableView beginUpdates];
[self.tableView endUpdates];
tableview 单元格高度的更改将使用 heightForRowAtIndexPath 自动计算,并且更改也会被动画化.
Changes to the tableview cells' heights will automatically be calculated with heightForRowAtIndexPath and the changes will be animated too.
事实上,您甚至可以在 didSelectRowAtIndexPath
中选择单元格,而不是使用单元格上的按钮来执行此操作.
In fact, instead of a button on your cell that does this, you might even just make selecting the cell do this in didSelectRowAtIndexPath
.
这篇关于UITableViewCell 点击展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!