如何动态调整 UITableViewCell 的高度 [英] How to dynamically resize UITableViewCell height

查看:39
本文介绍了如何动态调整 UITableViewCell 的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有经典的分组 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屋!

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