I need to reload the section excluding the header after I do some sort on my tableview data. That's to say I just want to reload all the rows in the section. But I don't find a easy way to make it after I search for a while.
reloadSections(sectionIndex, with: .none)
not works here, for it will reload the whole section including the header, footer and all the rows.
So I need to use reloadRows(at: [IndexPath], with: UITableViewRowAnimation)
instead. But how to get the whole indexPaths for the all the rows in the section.
Iterate over the index paths in a section using the numberOfRows inSection method of UITableView. Then you can build your IndexPath array:
You can get the indexPaths for reloading like this…
There's no need to reload non-visible cells, as they will be updated when
cellForRow(at indexPath:)
is calledYou can use below function get IndexPath array in a given section.
Or
You can get all the visible index paths directly, and then filter them however you want, i.e.
In my opinion, you don't need reload whole cells in the section. Simply, reload cells which is visible and inside section you need to reload. Reload invisible cells is useless because they will be fixed when
tableView(_:cellForRowAt:)
is called.Try my below code