UITableView:自适应单元格高度 [英] UITableView: Adaptive cell height

查看:120
本文介绍了UITableView:自适应单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道自适应细胞高度的最佳策略.单元格首先知道在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屋!

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