Reputation: 337
I have items in a tableview
, and i want to reload or update the tableview
data , except the first row or the first indexpath of the tableview.
let visibleIndex = self.tableView.visibleCells.compactMap {
tableView.indexPath(for: $0) }
self.tableView.reloadRows(at: visibleIndex, with: .automatic)
However this reloads all the visible cells , how do i reload all the visible cells except the first row
Upvotes: 1
Views: 4390
Reputation: 318854
No need to get the visible cells. Use indexPathsForVisibleRows
and remove the index path for section 0, row 0.
let allButFirst = (self.tableView.indexPathsForVisibleRows ?? []).filter { $0.section != 0 || $0.row != 0 }
self.tableView.reloadRows(at: allButFirst, with: .automatic)
Upvotes: 10
Reputation: 100533
Assuming the first visible cell is the 1 on the most top You can do
self.tableView.reloadRows(at: Array(visibleIndex.dropFirst()), with: .automatic)
Or if not
let visibleIndex = self.tableView.visibleCells.compactMap {
tableView.indexPath(for: $0) }.filter { $0.row != 0 }
self.tableView.reloadRows(at: visibleIndex, with: .automatic)
==
let visibleIndex:[IndexPath] = self.tableView.visibleCells.compactMap { item in
let index = self.tableView.indexPath(for:item)!
return index.row != 0 ? index : nil
}
Upvotes: 3