Search code examples
ioscocoa-touchios5

How does UITableViewRowAnimationAutomatic determine which animation to use?


The iOS 5 SDK introduced a new animation type for table cell insertions and deletions: UITableViewRowAnimationAutomatic. Apple's documentation for this value simply states:

The table view chooses an appropriate animation style for you.

So, err, how does this work, exactly? What factors does the table view take into account? The length of the table? The visible data? The phase of the moon?


Solution

  • It depends on where the row is being inserted.

    Normally, if you're manipulating rows at the start or end of a section and choose an inappropriate animation, the row might be displayed behind the section header/footer as it animates. The purpose of UITableViewRowAnimationAutomatic is to let the table view automatically select an animation that looks good.

    For example, when a row is being inserted at the beginning of a section, the table view will use UITableViewRowAnimationBottom. When it's is being inserted at the end of a section, the table view will use UITableViewRowAnimationTop.

    The WWDC 2011 session "UITableView Changes, Tips, Tricks" goes into more detail at around 3:25.