Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 554
Brant Bobby Avatar asked Oct 31 '11 20:10

Brant Bobby


People also ask

What class does UITableView inherit from?

TableView can be defined as the view which can arrange the data using rows in a single column. It is used in almost every iOS application, for example, contacts, facebook, Instagram, etc. The tableview is the instance of the UITableView class, which inherits the UIScrollView class.

What is UITableView in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+

What does TableView reload data do?

reloadData()Reloads the rows and sections of the table view.

How do I get indexPath from cell Swift?

add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.


1 Answers

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.

like image 187
Brant Bobby Avatar answered Oct 21 '22 04:10

Brant Bobby