Unit 4: TableViews - Practice Quiz
1 Which UIKit class is used to display a vertically scrolling list of rows?
2
Which protocol supplies row content to a UITableView?
3
Which protocol commonly handles row selection events in a UITableView?
4 Which data source method tells a table view how many rows to display in a section?
tableView(_:didSelectRowAt:)
tableView(_:heightForRowAt:)
tableView(_:numberOfRowsInSection:)
tableView(_:titleForHeaderInSection:)
5 Which method is used to provide a cell for a particular table row?
tableView(_:canEditRowAt:)
tableView(_:viewForFooterInSection:)
tableView(_:cellForRowAt:)
tableView(_:didSelectRowAt:)
6
Why is dequeueReusableCell(withIdentifier:for:) used when creating table rows?
7 Which class is normally subclassed to create a custom table view cell?
8 What is the purpose of a table cell's reuse identifier?
9
Where are custom labels and image views commonly added inside a UITableViewCell?
navigationItem
backgroundView only
tableHeaderView
contentView
10 Which table view style visually separates rows into groups?
11
What does an IndexPath identify in a table view?
12 Which method provides titles for a table view's section index?
numberOfSections(in:)
sectionIndexTitles(for:)
tableView(_:didSelectRowAt:)
tableView(_:heightForHeaderInSection:)
13 Which property sets a view above all sections of a table view?
tableHeaderView
contentInset
sectionHeaderHeight
tableFooterView
14 Which property sets a view below all sections of a table view?
sectionFooterHeight
contentOffset
tableFooterView
tableHeaderView
15 Which UIKit class is designed to display an image in a table cell?
16 Which delegate method is called when the user taps a table row?
tableView(_:cellForRowAt:)
tableView(_:didSelectRowAt:)
tableView(_:numberOfRowsInSection:)
tableView(_:titleForFooterInSection:)
17 How can the selected model item usually be found after a row is tapped?
IndexPath
18 Which method removes the visual selection highlight from a table row?
deleteRows(at:with:)
deselectRow(at:animated:)
reloadRows(at:with:)
scrollToRow(at:at:animated:)
19 Which method pushes a new view controller onto a navigation stack?
pushViewController(_:animated:)
popViewController(animated:)
dismiss(animated:completion:)
reloadData()
20 What is commonly passed to a detail view after a user selects a table row?
21
A view controller contains a UITableView, but no rows appear even though the data array has values. Which pair of table-view data source methods must normally be implemented to display rows?
tableView(_:didSelectRowAt:) and tableView(_:heightForRowAt:)
tableView(_:numberOfRowsInSection:) and tableView(_:cellForRowAt:)
numberOfSections(in:) and tableView(_:viewForHeaderInSection:)
tableView(_:willDisplay:forRowAt:) and tableView(_:accessoryButtonTappedForRowWith:)
22
A table displays the contents of cities, a Swift array of city names. Which implementation correctly reports the number of rows in a single section?
return cities[indexPath.row].count
return cities.count - 1
return tableView.numberOfSections
return cities.count
23
Which code most appropriately obtains a reusable standard cell registered with the identifier CityCell?
tableView.cellForRow(at: indexPath, identifier: "CityCell")
UITableViewCell.dequeue(withIdentifier: "CityCell", from: tableView)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CityCell")
tableView.dequeueReusableCell(withIdentifier: "CityCell", for: indexPath)
24
A view controller declares tableView.dataSource = self. What must be true for this assignment to work correctly?
UITableViewDataSource
UITableView
25
A prototype cell contains labels connected to properties in ProductCell. What should cellForRowAt do before accessing those properties?
UITableViewCell
ProductCell
ProductCell
26 A custom cell shows incorrect images after rapid scrolling because images are loaded asynchronously. Which technique best reduces this reuse-related problem?
numberOfRowsInSection
prepareForReuse()
27 A cell uses Auto Layout and contains a multiline description label. Which configuration supports a row height based on the label's content?
automaticDimension and provide complete vertical constraints
didSelectRowAt after the row is tapped
28
A data model is [["Apple", "Apricot"], ["Banana"]]. If each inner array represents one section, what should numberOfSections(in:) return?
2
3
data[0].count + data[1].count + 1
1
29
For sectioned data stored in itemsBySection, which expression retrieves the model for a requested table row?
itemsBySection[indexPath.row + indexPath.section]
itemsBySection.first?[indexPath.section + indexPath.row]
itemsBySection[indexPath.row][indexPath.section]
itemsBySection[indexPath.section][indexPath.row]
30
An indexed contacts table displays sections A, B, and C. Which data source method supplies the titles shown in the index along the table's edge?
tableView(_:numberOfRowsInSection:)
tableView(_:viewForFooterInSection:), which creates a separate footer containing all alphabetical index labels
sectionIndexTitles(for:)
tableView(_:titleForHeaderInSection:)
31
What is the main visual purpose of initializing a table view with the .grouped style?
32 Which method is appropriate when every section header only needs a simple text title?
tableView(_:commit:forRowAt:)
tableView(_:didSelectRowAt:)
tableView(_:cellForRowAt:)
tableView(_:titleForHeaderInSection:)
33 A developer wants one banner above the entire table, not a separate banner for each section. Which property should be assigned?
tableView.sectionHeaderHeight
tableView.tableHeaderView
tableView.backgroundView
tableView.tableFooterView, followed by reversing the table's coordinate system so the footer appears at the top
34 A standard table cell should display a small image beside its text. Which assignment is most direct?
cell.backgroundView = UIImage(named: "icon")
tableView.image = UIImage(named: "icon")
cell.textLabel?.layer.contents = "icon"
cell.imageView?.image = UIImage(named: "icon")
35 A custom section header contains an image and two labels. Which delegate method should return this header view?
tableView(_:titleForHeaderInSection:)
tableView(_:willSelectRowAt:)
tableView(_:accessoryButtonTappedForRowWith:)
tableView(_:viewForHeaderInSection:)
36
A table displays names from people. Which statement correctly obtains the selected person's name inside tableView(_:didSelectRowAt:) for a single-section table?
let name = people[tableView.numberOfSections]
let name = people[indexPath.row]
let name = people[indexPath.row + 1], because visible table rows use one-based indexing during selection
let name = people[indexPath.section]
37 After showing information about a selected row, an app should immediately remove the row's highlight. Which call is appropriate?
tableView.setEditing(false, animated: true)
tableView.reloadRows(at: [indexPath], with: .none)
tableView.deselectRow(at: indexPath, animated: true)
tableView.deleteRows(at: [indexPath], with: .fade)
38
A storyboard segue named ShowDetails should run when a row is selected. Which call is appropriate inside didSelectRowAt?
navigationController?.popViewController(animated: true)
tableView.pushViewController(withIdentifier: "ShowDetails", sender: indexPath)
performSegue(withIdentifier: "ShowDetails", sender: indexPath)
present("ShowDetails", animated: true)
39
Before a segue displays DetailViewController, where should the selected model normally be assigned to the destination controller?
numberOfSections(in:)
prepare(for:sender:)
deinit, after the navigation transition has already completed
tableView(_:heightForRowAt:)
40
A table is inside a navigation controller. Which code pushes an already-created detailController onto the navigation stack?
navigationController?.setViewControllers([], animated: true)
navigationController?.pushViewController(detailController, animated: true)
navigationController?.present(detailController, completion: true)
tableView.pushViewController(detailController, animated: true)
41
A table displays three items. To delete row 1, the controller calls tableView.deleteRows(at:with:) and removes the corresponding model element only in the animation completion handler. UIKit reports an invalid update. Which change correctly preserves the table's data-source invariant?
performBatchUpdates.
42
A searchable table maintains allItems and filteredItems. After filtering, numberOfRowsInSection returns allItems.count, while cellForRowAt reads filteredItems[indexPath.row]. What is the most robust correction?
allItems in cellForRowAt until filtering has fully completed.
reloadData from the exception handler.
43 A custom cell uses automatic row height. Its label is constrained to the leading and trailing edges, but only its top edge is constrained vertically. Some rows collapse to the estimated height. Which correction addresses the underlying problem?
estimatedRowHeight until every label is visible.
cellForRowAt.
contentView.
44
A reused cell starts an asynchronous image download in cellForRowAt. Fast scrolling occasionally places an image in the wrong row. Which design most directly prevents this race?
45 A reusable custom cell conditionally sets its subtitle color and accessory type. After scrolling, cells sometimes retain values from earlier rows. Which configuration policy is correct?
prepareForReuse.
46
An indexed table returns [UITableView.indexSearch, "A", "B"] from sectionIndexTitles(for:). The search icon should scroll to the search UI rather than a data section. What should tableView(_:sectionForSectionIndexTitle:at:) return for that icon?
NSNotFound after separately scrolling or activating the search UI.
0 and place the search UI inside the first data section.
1 because data-section numbering follows the search icon.
47
A controller uses UILocalizedIndexedCollation and returns the tapped index directly as the section number. It removes empty alphabetic sections from the table, causing index taps to open incorrect sections. Which structure preserves direct index-to-section mapping?
48
A diffable snapshot for a grouped table attempts to append items to section ID favorites before that section has been appended to the snapshot. What is the correct snapshot construction order?
49
A multiline Auto Layout view is assigned to tableView.tableHeaderView, but its height remains incorrect after text changes. Which sequence correctly resizes it?
reloadSections and let the table infer the header's intrinsic height.
tableHeaderView.
tableView(_:heightForHeaderInSection:).
50
A custom section header subclasses UITableViewHeaderFooterView and is dequeued for reuse. A badge hidden in one section unexpectedly remains hidden in another. What is the correct remedy?
willDisplayHeaderView only.
51
An asynchronously loaded image changes the intrinsic height of a view assigned to tableFooterView, but the table continues using the old footer height. What should happen after the image arrives?
tableFooterView.
reloadSectionIndexTitles to force the footer layout to update.
52 Selected rows display checkmarks, but the checkmarks move to unrelated rows after scrolling. The controller currently toggles only the tapped cell's accessory type. Which design is correct?
53
A single-choice table uses a diffable data source and stores selectedItemID. When the user chooses another item, which update most efficiently keeps checkmarks correct?
selectedItemID.
54
A switch inside a custom cell changes the item's selected state. Relying on didSelectRowAt fails because operating the switch does not consistently select the row. What is the strongest solution?
didSelectRowAt directly from the switch's value-change handler.
55 A row selection begins navigation while a diffable snapshot may reorder rows. The destination must receive the correct object. What value should be captured when selection occurs?
56 A storyboard-based table controller should push a detail controller when embedded in a navigation controller, but adapt appropriately in other containers. Which segue action best matches this requirement?
show segue and pass the selected model in prepare(for:sender:).
present(_:animated:).
57
Selecting a row sometimes opens two detail controllers. The prototype cell has a storyboard segue to the detail scene, and didSelectRowAt also calls performSegue. What is the correct fix?
deselectRow before performing the second navigation transition.
performSegue in didSelectRowAt.
58 Applying a diffable snapshot terminates with an error stating that identifiers are not unique. Two visually identical rows represent separate records. What is the correct identity strategy?
59
A controller calls dequeueReusableCell(withIdentifier:for:) and crashes immediately. The identifier is spelled correctly, but no prototype cell or registration exists. Which statement is correct?
nil, so the caller should construct a fallback cell.
60 A background task fetches records and directly applies a diffable snapshot while the user scrolls. Intermittent UI warnings and inconsistent updates occur. Which concurrency design is appropriate?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →