6

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()?

vacawama
  • 133,454
  • 26
  • 238
  • 261
Junya Kono
  • 701
  • 2
  • 7
  • 14
  • 1
    'It did not result as expected" - what happened? That is, what went wrong when you called `reloadRows`? – paper1111 Jun 24 '17 at 08:14
  • I write an animation. but, it does not matter. What is the difference between the `reloadData` and `reloadRows` internal implementation? – Junya Kono Jun 24 '17 at 08:18

1 Answers1

4

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

Daniel Isaac
  • 745
  • 5
  • 14
  • I don't see the answer what is the difference. Disregarding animations and if you specify to reload all rows. – jesse Jun 09 '20 at 09:36