Monotouch:强制 UITableView 重新计算每个单元格的高度而不重新加载数据 [英] Monotouch: Force UITableView to recalculate height of each cell without reloading data

查看:32
本文介绍了Monotouch:强制 UITableView 重新计算每个单元格的高度而不重新加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 OwnerDrawnElement 创建的自定义单元格,其中包含可自动调整大小的 UITextView.当文本更改时,应该进行适当的布局重绘和单元格高度重新计算.问题是如何保存键盘打开.UITableView 中有一个方法 - ReloadRows 实际上以某种方式帮助了我.我不能为我的手机打电话,因为它是第一响应者,我不能辞职.但是当我为另一个单元格调用它时,我的单元格正在根据我的需要调整大小,但是我没有必要重新绘制另一个单元格.所以我想知道调用什么方法来重新布局 UITableView 不重新加载数据?!当您上下滚动时,可能会调用相同的方法,单元格变得可见并重新计算高度.

I have a custom cell created using OwnerDrawnElement with autoresizeable UITextView in it. When text changed there should be appropriate layout redraw and cell height recalculation. The problem is how to preserve keyboard opened. There is a method inside UITableView - ReloadRows which actually helped me in some fashion. I can't call it for my cell because it is the first responder and can't I cant resign it. But when I call it for another cell my cell is getting resized as I wanted but I have unnecessary another cell redraw. So I wonder what method is called to relayout UITableView NOT reload data?! The same method is probable called when you scroll up and down, cells become visible and height is recalculated.

我尝试过标准的 SetNeedsDisplay()、SetNeedsLayout()、ReloadInputViews()、LayoutSubviews(),但它没有做同样的事情.也许我需要以不同的方式使用它们.我试图为单元格和整个 tableview 对象调用它们.

I've tried standard SetNeedsDisplay(), SetNeedsLayout(), ReloadInputViews(), LayoutSubviews(), but it didn't do the same. Maybe I need use them somehow differently. I've tried to call them for cell and whole tableview objects.

我研究了 ReloadRows 方法,发现它调用了一些 API 的东西:

I've looked into ReloadRows method and found out that it calls some API stuff:

Messaging.void_objc_msgSendSuper_IntPtr_int(base.SuperHandle, UITableView.selReloadRowsAtIndexPathsWithRowAnimation_, nSArray.Handle, (int)withRowAnimation);

Messaging.void_objc_msgSendSuper_IntPtr_int(base.SuperHandle, UITableView.selReloadRowsAtIndexPathsWithRowAnimation_, nSArray.Handle, (int)withRowAnimation);

所以它不是什么方法强制tableview在不重新加载数据的情况下重新计算每个单元格的高度.

So it doesn't what method forces tableview to recalculate height of each cell without reloading data either.

你能帮我解决这个问题吗?

Can you help me with that?

推荐答案

尝试更新单元格框架,然后调用 UITableView 的空更新块:

Try to update cells frames, then call UITableView's empty update block:

tableView.BeginUpdates();
tableView.EndUpdates();

这篇关于Monotouch:强制 UITableView 重新计算每个单元格的高度而不重新加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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