UITableView:自适应单元格高度 [英] UITableView: Adaptive cell height
问题描述
我想知道自适应细胞高度的最佳策略.单元格首先知道在cellForRowAtIndexPath
方法中创建它们时的高度(它们包含一些文本框和图像).
我的想法是使用单元格识别键将单元格的高度存储在NSMutableDictionary
中.
问题在于heightForRowAtIndexPath:
方法在创建单元格之前被称为,然后才被创建.
I'd like to know the best strategy for adaptive cell heights. The cells first know how high they will be when they are created (they contain some textboxes and images) in the cellForRowAtIndexPath
method.
My idea was to store the cell's height in a NSMutableDictionary
with a cell identifiying key.
The problem is that the heightForRowAtIndexPath:
method is called before the cells are created and only then.
通常如何管理?
推荐答案
如果要调整单元格的大小(即-使heightForRowAtIndexPath
方法被调用),则可以使用空的beginUpdates-endUpdates块:
If you want to resize your cells (that is - to make heightForRowAtIndexPath
method get called) you can use empty beginUpdates - endUpdates block:
[table beginUpdates];
[table endUpdates];
这将强制UITableView更新其几何形状,并且单元格的高度将被更新
That will force UITableView to update its geometry and cells heights will be updated
这篇关于UITableView:自适应单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!