TableViewUpdater
is a class, responsible for animating datasource updates.
Sometimes it's convenient to know, when data is updated, for example to hide UITableView, if there's no data. TableViewUpdater
has willUpdateContent
and didUpdateContent
properties, that can help:
updater.willUpdateContent = { update in
print("UI update is about to begin")
}
updater.didUpdateContent = { update in
print("UI update finished")
}
Please keep in mind, that those closures will not be called if you directly invoke tableView.reloadData()
. If you need to call reloadData
and trigger those closures, please call:
manager.tableViewUpdater?.storageNeedsReloading()
You can customize section and row animations:
updater.insertSectionAnimation = .automatic
updater.deleteSectionAnimation = .fade
updater.reloadSectionAnimation = .none
updater.insertRowAnimation = .automatic
updater.deleteRowAnimation = .fade
updater.reloadRowAnimation = .none
DTTableViewManager
uses TableViewUpdater
class by default. While usually, you don't need to configure anything additional with TableViewUpdater
, one exception to this rule is CoreData and CoreDataStorage
.
When setting up CoreDataStorage with DTTableViewManager
and DTCollectionViewManager
, consider using special CoreData updater:
manager.collectionViewUpdater = manager.coreDataUpdater()
manager.tableViewUpdater = manager.coreDataUpdater()
This special version of updater has two important differences from default behavior:
- Moving items is animated as insert and delete
- When data model changes,
update(with:)
method andhandler
closure are called to update visible cells without explicitly reloading them.
Those are recommended by Apple approaches to handle NSFetchedResultsControllerDelegate
updates with UITableView
and UICollectionView
.
If your UITableView
is not on screen, it's updates are not required to be animated. For performance reasons you may want to disable offscreen animations:
manager.tableViewUpdater.animateChangesOffScreen = false