UITableView Magic

I’ve been working on a little prototype for something and wanted to have table cells that expand or collapse their height when you tap on them.

I just discovered this post, which taught me a bit of simple magic that I thought was worth sharing.

If you simply need to animate the change in a cell’s height (but don’t need to change its data or cell itself), you can simply call:

[tableView beginUpdates];
[tableView endUpdates];

That’s it. No reloadRowsAtIndexPaths: withRowAnimation: . You should call that if you need to update your content, or if you need to show a different cell for that expanded or collapsed state.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s