maxsokolov / TableKit

Type-safe declarative table views.
MIT License
706 stars 74 forks source link

Update sections with animation #69

Closed denisenkoaj closed 7 years ago

denisenkoaj commented 7 years ago

Max hello! Could you say, how i can implement reloading section with animation? Usually i do it like this:

let range = NSMakeRange(0, (self?.tableView.numberOfSections)!) let sections = NSIndexSet(indexesIn: range) self?.tableView.reloadSections(sections as IndexSet, with: .automatic)

I tried a lot of different ways to do it with tablekit, but i have runtime errors that either sections or rows are not correctly calculated by the table itself before and after the update.

maxsokolov commented 7 years ago

Hi @denisenkoaj

This is pretty simple: 1) Update your model/viewModel (rows or sections) 2) Perform updates on a table view

For example

tableDirector.replaceSection(at: 1, with: newSection)

tableView.beginUpdates()
tableView.reloadSections([1], with: .automatic)
tableView.endUpdates()

Check TableDirector.swift file // MARK: - Sections manipulation or TableSection.swift file // MARK: - Public -

denisenkoaj commented 7 years ago

Thank you! Everything is work 👍