What is the difference between tableView.reloadData()
and tableView.reloadRows(at: [IndexPath],with: .none)
?
I know that cells will reload everything after tableView.reloadData()
I tried the following.
cell.count = 2
indexPath
= [0,0]
and [0,1]
tableView.reloadRows(at: [[0,0] as IndexPath],with: .none)
tableView.reloadRows(at: [[0,1] as IndexPath],with: .none)
However, it did not result as expected.
Does the behavior differ between reloading all of tableView.reloadRows()
with cells and reloading with tableView.reloadData()
?
Check out the apple documentation for this -
1. reloadData() :
Reloads the rows and sections of the table view.
Description : Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view’s delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates() and endUpdates().
2. reloadRows(at:with:) :
Reloads the specified rows using an animation effect.
Description:
Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.
When this method is called in an animation block defined by the beginUpdates() and endUpdates() methods, it behaves similarly to deleteRows(at:with:). The indexes that UITableView passes to the method are specified in the state of the table view prior to any updates. This happens regardless of ordering of the insertion, deletion, and reloading method calls within the animation block.
https://developer.apple.com/documentation/uikit/uitableview/1614862-reloaddata https://developer.apple.com/documentation/uikit/uitableview/1614935-reloadrows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With