Reputation: 478
I'm a little confused with inserting cell into a table view.
When I call tableView.insertRows(at: [indexPath], with: .left)
tableView
not update immediately after it, inside called function. I think it's call some relevant delegate and data source methods, but which ones?
Also, I have seen that some guys call insertRows
with tableView.beginUpdates()
and tableView.endUpdates()
. Why do we need to do this if the update happens without these two methods?
Upvotes: 0
Views: 52
Reputation: 1348
Tableview DataSource methods will be called, to begin a series of method calls that insert, delete, or select rows and sections of the table view, you need to call beginUpdates()
followed by endUpdates()
Upvotes: 1
Reputation: 100533
numberOfRows
&& cellForRowAt
are called when you do insertion , you need begin & end updates to prevent subsequent calls to numberOfRows in case you have a heavy calls to insertion / deletion to avoid exceptions like number of rows / section before the update isn't equal after adding / removing
now it's recommended to use
https://developer.apple.com/documentation/uikit/uitableview/2887515-performbatchupdates
inside
https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates
Upvotes: 2