drunkcamel
drunkcamel

Reputation: 915

Monotouch: Force UITableView to recalculate height of each cell without reloading data

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.

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.

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);

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

Can you help me with that?

Upvotes: 2

Views: 1584

Answers (1)

Maxim Korobov
Maxim Korobov

Reputation: 2572

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

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

Upvotes: 5

Related Questions