Activity 1
Build a sectioned lesson list
Group lessons by module and display headers, completion accessories, and selection callbacks.
Hint: Create a section model instead of calculating groups repeatedly in data-source methods.
UIKit Development
Present efficient vertical lists with reusable cells, self-sizing content, selection, and clean data ownership.
Before you begin
Learning stage
UITableView presents a vertically scrolling sequence of sections and rows while reusing a limited pool of cells. The data source reports structure and configures cells; the delegate handles selection and display behavior. An index path describes a current location, not durable item identity.
Register a cell class or use a cell registration, dequeue for every requested index path, and fully configure every visible state because a reused cell retains prior values. With a complete vertical constraint chain and automatic dimensions, rows can self-size for Dynamic Type and variable content.
Selection should resolve the current model and emit a semantic action. The model collection remains the source of truth; views do not own domain data. For complex animated mutations, diffable data sources reduce manual coordination, which a later lesson covers in depth.
Learning stage
A simple table controller fully configures each reused list cell from immutable row data.
final class LessonListViewController: UITableViewController {
private var lessons: [Lesson] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Lesson")
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 64
}
override func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
lessons.count
}
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Lesson", for: indexPath)
let lesson = lessons[indexPath.row]
var content = cell.defaultContentConfiguration()
content.text = lesson.title
content.secondaryText = lesson.durationText
cell.contentConfiguration = content
cell.accessoryType = lesson.isComplete ? .checkmark : .disclosureIndicator
return cell
}
}Learning stage
Connect the UIKit concept to complete, maintainable application features.
Learning stage
Identify lifecycle, ownership, identity, layout, accessibility, and user-experience risks.
Learning stage
Build the behavior in a small Xcode project and inspect it across realistic states.
Activity 1
Group lessons by module and display headers, completion accessories, and selection callbacks.
Hint: Create a section model instead of calculating groups repeatedly in data-source methods.
Activity 2
Add optional badges and images, scroll rapidly, then ensure every conditional property is reset during configuration.
Hint: Test rows with and without each optional value.
Learning stage
Answer each question before revealing the explanation.
QUESTION 1
It may still contain state from a previously displayed item
Reuse changes which model a cell represents, so all visible state must be derived again.
QUESTION 2
Its location can change when sections or rows are inserted, removed, sorted, or filtered.
Use a stable model ID when work must remain attached to the same item.
Learning stage
Explain the design in terms of lifecycle, identity, ownership, system behavior, and trade-offs.
Short answer: The table recycles offscreen cells, so configuration must overwrite every state and asynchronous work must follow stable identity.
Only enough cells for the visible region and a buffer are created. As cells are reused for new index paths, stale labels, accessories, images, or tasks can appear unless configuration is complete and cancellation/identity checks are in place. The model, not the cell, remains authoritative.
Possible follow-ups
Learning stage
Table views efficiently display vertical data by reusing cells. Reliable implementations derive every cell state from the model and treat index paths as temporary locations.