Checklists - Sorting the lists (pg. 332) - Question on how it works

Hey all, I’m curious to exactly how tableView.reloadData() works in sorting the lists and why it allows us to remove tableView.insertRows. I believe I have a general understanding of how it works but want to make sure it is correct.

My understanding is that we append to the list, order the list, then reload the view. Reloading the view causes the numberOfRows method to return 1 more than before, then cellForRowAt creates all the cells over again including the new one but this time in sorted order.

Is this how it all works?

Hi @joeyr42

You are correct, the reloadData() function reloads all the data for tableView, it also reloads all the cells and sections that need to be displayed on the screen. The insertRows() methods only creates new cells and displays them (if needed) and it doesn’t affect the existing cells.
For more information please check the documentation: Apple Developer Documentation, Apple Developer Documentation

Nikita

This topic was automatically closed after 166 days. New replies are no longer allowed.