What's the difference between tableView.reloadData and tableView.reloadRows?

What is the difference between tableView.reloadData()

and tableView.reloadRows(at: [IndexPath],with: .none)

?

I know the 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, this is not as expected.

Does the behavior differ between reloading all tableView.reloadRows()

with cells and reloading with all tableView.reloadData()

?

+3


source to share


1 answer


Look at the apple documentation for this -

1.reloadData ():

Reloads the rows and sections of the table view.

Description . Call this method to reload all data that is used to build the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view displays only the rows that are visible. It adjusts offsets if the table shrinks as a result of a reload. A table or data source delegate view calls this method when it wants the table view to completely reload its data. It should not be called in methods that insert or remove lines, especially in an animation block implemented with calls to beginUpdates () and endUpdates ().

2.reloadRows (at: with :):



Reloads the specified lines using the animation effect.

Description :

Reloading a row causes the table view to query its data source for a new cell for that row. The table brings the new cell to life as it brings the old row to life. Call this method when you want to alert the user that the cell value is changing. If, however, notifying the user is not important, i.e. You just want to change the value displayed by the cell, you can get the cell for a specific row and set its new value.

When this method is called within the animation block defined by the beginUpdates () and endUpdates () methods, it behaves similarly to deleteRows (at: with :). The indices that the UITableView passes to the method are specified in the table's view state before any updates. This happens regardless of the order of the insert, delete, and reload requests in the animation block.

https://developer.apple.com/documentation/uikit/uitableview/1614862-reloaddata https://developer.apple.com/documentation/uikit/uitableview/1614935-reloadrows

+1


source







All Articles