滚动时如何禁用UITableView的单元格重新加载? [英] How can I disable UITableView's cells reloading when scrolling it?

查看:68
本文介绍了滚动时如何禁用UITableView的单元格重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向上或向下滚动时不需要UITableView来重新加载其单元格时,就遇到了问题。简而言之,我创建了自定义单元格,其中包含用户可以单击的内容。例如,我有一个 UILabel ,其中包含很多文本,虽然不能完全显示,但是用户可以单击按钮并展开文本,因此也可以添加标签。我通过 [tableview beginUpdates] [tableview endUpdates] 实现的所有功能。但是,当我单击按钮并展开文本或图像并向下滚动到其他单元格,然后向上 UITableView 时,当然会重新加载单元格的内容,文本再次隐藏,但是单元格保持相同大小这看起来很丑。我可以通过某种方式自定义 UITableView 回收机制或更新内部单元缓存吗?

I've encountered with the problem when I don't need UITableView to reload its cells when I scroll it upwards and downwards. In simple words i created custom cell's which have content that user can expand by clicking on it. For example I have a UILabel with a lot of text in it which doesn't display fully but user can click on button and expand text and consequently a label. All this I implement via [tableview beginUpdates] and [tableview endUpdates]. But when I click button and expand text or image and scroll down to other cells and then up UITableView of course reload my cell's content and text is hiding again but cell remains the same size and this looks ugly. Can I in some way customise UITableView recycling mechanism or update internal cell cache?

推荐答案

您不能禁用重新加载。正确的解决方案是确保保存每个单元格的状态(是否已扩展),以便在由于滚动而需要重新加载单元格时,为当前状态提供适当的高度和内容。

You cant disable the reloading. The proper solution is to ensure you are saving the state of each cell (expanded or not) so when the cell needs to be reloaded due to scrolling, you provide the proper height and content for the current state.

这篇关于滚动时如何禁用UITableView的单元格重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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