Warm tip: This article is reproduced from stackoverflow.com, please click
ios swift uitableview reloaddata indexpath

What's the most efficient way to reload all rows in a tableview except the first cell?

发布于 2020-03-27 10:29:45

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

Questioner
BigFire
Viewed
151
rmaddy 2019-07-04 01:35

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)