UITableViewCell在点击时展开 [英] UITableViewCell expand on click

查看:108
本文介绍了UITableViewCell在点击时展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我们有一个自定义的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屋!

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