如何动态调整UITableViewCell高度 [英] How to dynamically resize UITableViewCell height
问题描述
我在每个单元格中都有经典的UITableView和可编辑的UITextViews。这个文本视图可以是单行或多行的,我希望单元格在用户写入时增加其高度,文本开始换行。
I have the classical grouped UITableView with editable UITextViews inside every cell. This text views can be single or multi-lined, and I want the cell to increase its height as the user writes and the text starts a new line.
我的问题是:我是否需要重新加载整个表格以增加单元格的高度?有没有其他方法?
我一直在搜索,以前的答案和教程只是讨论如何计算文字高度,如何实现heightForRowAtIndexPath ...我已经知道的事情。我担心的是,为了达到我想要的效果,每次用户输入一个新角色时,我都必须计算高度并重新加载表格,我觉得这个角色并不干净或高效。
I've been searching a lot, and previous answers and tutorials just talk about how to calculate text height, how to implement heightForRowAtIndexPath... things that I already know. My concern is that, to achieve what I want, I will have to calculate height and reload the table every time the user enters a new character, which I don't find very clean or efficient.
谢谢。
推荐答案
您不必总是重新加载整个表格。你只需重新加载那一行。
You do not always have to reload the entire table. You can instead just reload that one row.
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
这篇关于如何动态调整UITableViewCell高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!