可以在不重新加载表视图的情况下更改UITableViewCell的高度吗? [英] Can the height of a UITableViewCell be changed without reloading the table view?

查看:109
本文介绍了可以在不重新加载表视图的情况下更改UITableViewCell的高度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调整UITableViewCell的大小而不重新加载表视图。

I'm trying to resize a UITableViewCell without reloading the table view.

我的UITableViewCell包含一个UITextView,因此用户可以输入可能是多行的列表项(约四个最大长度。现在,我每次用户按下返回键时都会调整文本视图的大小,但我还要更改表格视图单元格的高度

My UITableViewCell contains a UITextView so users can input list items that may be several lines (about four max) in length. Right now, I'm resizing the text view each time the user presses the return key, but I'd like to change the height of the table view cell as well.

我遇到的主要问题是重新加载表格视图的数据会使文本视图失去焦点。有没有办法在不重新加载表视图的情况下更改UITableViewCell的高度,让用户继续在文本视图中输入文本?

The main problem I'm running into is that reloading the table view's data makes the text view lose focus. Is there any way to change the height of the UITableViewCell without reloading the table view, letting the user continue to input text in the text view?

推荐答案

要调整表格视图行的大小,请尝试发送:

To resize a table view row, try sending:

[tableView beginUpdates];
[tableView endUpdates];

如果您为该单元格返回了正确的高度,这些消息会紧接着另一条消息。在 tableView:heightForRowAtIndexPath:方法中。该行应该是动画。您应该能够使用其边界返回单元格的高度,或者只是知道您将单元格高度设置为。

These messages one immediately after the other should do the trick provided you have the correct height returned for that cell in the tableView:heightForRowAtIndexPath: method. The row should animate. You should be able to return the height of your cell using its bounds or just from knowing what you've set the cell height as.

显然tableView是名称您的表格视图。

Obviously "tableView" is the name of your table view.

这篇关于可以在不重新加载表视图的情况下更改UITableViewCell的高度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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