0

Is it appropriate to call [tableView beginUpdates] and [tableView endUpdates] in cellforRowAtIndexPath?

I am trying to dynamically expand cell heights based on the content within the cell. When I use [tableView beginUpates] and [tableView endUpdates] in cellForRowAtIndexPath, the output looks ok. However, once I start scrolling, data in the cells becomes ordered incorrectly and sometimes the bar separator between table cells disappears.

Should I not be using [tableView beginUpdates] and [tableView endUpdates] for this?

Thanks!

4

1 回答 1

0

You've got to specify your dynamic cell heights in heightForRowAtIndexPath because the table view wants to know its content size up-front. Any changes you make to the cell's frame in cellForRowAtIndexPath will be overridden by the table view, so what you're attempting won't work.

If your heights are derived from the cell's content, consider using the prototype approach outlined here. Also, if you can use a 3rd party library, check out TLIndexPathTools. It does dynamic cell height for free if your custom cell class implements the TLDynamicSizeView prototype. Try running the Dynamic Height sample project.

于 2013-07-06T17:57:16.533 回答