7.6 · UITableView, still asked and still everywhere

Collection views with list layouts are the modern choice, but table views are in nearly every existing codebase, and their rules for data consistency are the ones interviewers test.

Mental model. A table view never owns your data. It asks you for counts and cells, and trusts that your answers are consistent with the changes you tell it about.

The table view

Data source rules, sizing, and updates that crash.

  1. How does a UITableView get its rows, and why do batch updates crash when the data and the update disagree? 7.6.1 · L1
    A table view asks its data source for the number of sections and rows and for a cell per index path, and asks its delegate about behaviour (selection, row…
  2. Table view or collection view: which do you choose for new code? 7.6.2 · L2
    For new screens, prefer a collection view with a list configuration (UICollectionLayoutListConfiguration). It gives you the table look (separators, swipe…

More in UIKit