Unit 4: TableViews - Practice Quiz

INT372 — Iphone Application Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which UIKit class is used to display a vertically scrolling list of rows?

UITableView basics Easy
A. UITableView
B. UINavigationBar
C. UITabBarItem
D. UICollectionViewCell

2 Which protocol supplies row content to a UITableView?

UITableView basics Easy
A. UITableViewDataSource
B. UITextFieldDelegate
C. UITableViewDelegate
D. UINavigationControllerDelegate

3 Which protocol commonly handles row selection events in a UITableView?

UITableView basics Easy
A. UIApplicationDelegate
B. UITableViewDataSource
C. UITableViewDelegate
D. UIScrollViewDataSource

4 Which data source method tells a table view how many rows to display in a section?

Implementing simple table Easy
A. tableView(_:heightForRowAt:)
B. tableView(_:numberOfRowsInSection:)
C. tableView(_:titleForHeaderInSection:)
D. tableView(_:didSelectRowAt:)

5 Which method is used to provide a cell for a particular table row?

Implementing simple table Easy
A. tableView(_:cellForRowAt:)
B. tableView(_:viewForFooterInSection:)
C. tableView(_:canEditRowAt:)
D. tableView(_:didSelectRowAt:)

6 Why is dequeueReusableCell(withIdentifier:for:) used when creating table rows?

Implementing simple table Easy
A. To delete hidden cells
B. To sort visible cells
C. To reuse existing cells
D. To select multiple cells

7 Which class is normally subclassed to create a custom table view cell?

Customizing TableView cells Easy
A. UINavigationController
B. UITableViewController
C. UITableViewCell
D. UIViewController

8 What is the purpose of a table cell's reuse identifier?

Customizing TableView cells Easy
A. To identify reusable cell types
B. To identify table view controllers
C. To identify navigation destinations
D. To identify selected section titles

9 Where are custom labels and image views commonly added inside a UITableViewCell?

Customizing TableView cells Easy
A. Inside its tableHeaderView
B. Inside its navigationItem
C. Inside its contentView
D. Inside its backgroundView only

10 Which table view style visually separates rows into groups?

Grouped and indexed sections Easy
A. Compact
B. Grouped
C. Overlay
D. Plain

11 What does an IndexPath identify in a table view?

Grouped and indexed sections Easy
A. A section and row
B. A header and footer
C. A title and subtitle
D. A width and height

12 Which method provides titles for a table view's section index?

Grouped and indexed sections Easy
A. sectionIndexTitles(for:)
B. numberOfSections(in:)
C. tableView(_:didSelectRowAt:)
D. tableView(_:heightForHeaderInSection:)

13 Which property sets a view above all sections of a table view?

Adding header, footer, and image Easy
A. sectionHeaderHeight
B. contentInset
C. tableHeaderView
D. tableFooterView

14 Which property sets a view below all sections of a table view?

Adding header, footer, and image Easy
A. tableFooterView
B. tableHeaderView
C. sectionFooterHeight
D. contentOffset

15 Which UIKit class is designed to display an image in a table cell?

Adding header, footer, and image Easy
A. UITextView
B. UIImageView
C. UIProgressView
D. UILabel

16 Which delegate method is called when the user taps a table row?

Displaying item selected Easy
A. tableView(_:numberOfRowsInSection:)
B. tableView(_:didSelectRowAt:)
C. tableView(_:cellForRowAt:)
D. tableView(_:titleForFooterInSection:)

17 How can the selected model item usually be found after a row is tapped?

Displaying item selected Easy
A. Use the section header height
B. Use the cell reuse count
C. Use the table frame width
D. Use the row from IndexPath

18 Which method removes the visual selection highlight from a table row?

Displaying item selected Easy
A. reloadRows(at:with:)
B. deleteRows(at:with:)
C. scrollToRow(at:at:animated:)
D. deselectRow(at:animated:)

19 Which method pushes a new view controller onto a navigation stack?

Navigating to another view Easy
A. reloadData()
B. pushViewController(_:animated:)
C. dismiss(animated:completion:)
D. popViewController(animated:)

20 What is commonly passed to a detail view after a user selects a table row?

Navigating to another view Easy
A. The cell's reuse queue
B. The device's screen scale
C. The selected item's data
D. The table's background color

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?

UITableView basics Medium
A. tableView(_:didSelectRowAt:) and tableView(_:heightForRowAt:)
B. numberOfSections(in:) and tableView(_:viewForHeaderInSection:)
C. tableView(_:numberOfRowsInSection:) and tableView(_:cellForRowAt:)
D. 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?

Implementing simple table Medium
A. return tableView.numberOfSections
B. return cities.count
C. return cities[indexPath.row].count
D. return cities.count - 1

23 Which code most appropriately obtains a reusable standard cell registered with the identifier CityCell?

Implementing simple table Medium
A. tableView.dequeueReusableCell(withIdentifier: "CityCell", for: indexPath)
B. tableView.cellForRow(at: indexPath, identifier: "CityCell")
C. tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CityCell")
D. UITableViewCell.dequeue(withIdentifier: "CityCell", from: tableView)

24 A view controller declares tableView.dataSource = self. What must be true for this assignment to work correctly?

UITableView basics Medium
A. The view controller must conform to UITableViewDataSource
B. The view controller must inherit directly from UITableView
C. The view controller must implement every optional method from both the data source and delegate protocols
D. The table view must use the grouped presentation style

25 A prototype cell contains labels connected to properties in ProductCell. What should cellForRowAt do before accessing those properties?

Customizing TableView cells Medium
A. Convert the row index into a cell identifier and reconnect every outlet programmatically
B. Cast the table view to ProductCell
C. Create a new base UITableViewCell
D. Cast the dequeued cell to ProductCell

26 A custom cell shows incorrect images after rapid scrolling because images are loaded asynchronously. Which technique best reduces this reuse-related problem?

Customizing TableView cells Medium
A. Reload the entire table whenever an image request completes
B. Move all image-loading code into numberOfRowsInSection
C. Disable cell reuse by assigning a unique identifier to every row
D. Cancel old image requests and reset the image in 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?

Customizing TableView cells Medium
A. Use automaticDimension and provide complete vertical constraints
B. Set the row height to zero and remove the bottom constraint
C. Calculate the height only in didSelectRowAt after the row is tapped
D. Use a fixed row height and increase the table view's content inset whenever a long description is encountered

28 A data model is [["Apple", "Apricot"], ["Banana"]]. If each inner array represents one section, what should numberOfSections(in:) return?

Grouped and indexed sections Medium
A. 2
B. 3
C. data[0].count + data[1].count + 1
D. 1

29 For sectioned data stored in itemsBySection, which expression retrieves the model for a requested table row?

Grouped and indexed sections Medium
A. itemsBySection[indexPath.section][indexPath.row]
B. itemsBySection[indexPath.row][indexPath.section]
C. itemsBySection.first?[indexPath.section + indexPath.row]
D. itemsBySection[indexPath.row + indexPath.section]

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?

Grouped and indexed sections Medium
A. tableView(_:titleForHeaderInSection:)
B. tableView(_:numberOfRowsInSection:)
C. tableView(_:viewForFooterInSection:), which creates a separate footer containing all alphabetical index labels
D. sectionIndexTitles(for:)

31 What is the main visual purpose of initializing a table view with the .grouped style?

Grouped and indexed sections Medium
A. To force each section to use a custom cell subclass with rounded corners, shadows, and fixed spacing
B. To sort every section alphabetically without additional code
C. To present sections as visually separated groups
D. To merge all rows into one automatically indexed section

32 Which method is appropriate when every section header only needs a simple text title?

Adding header, footer, and image Medium
A. tableView(_:cellForRowAt:)
B. tableView(_:didSelectRowAt:)
C. tableView(_:titleForHeaderInSection:)
D. tableView(_:commit:forRowAt:)

33 A developer wants one banner above the entire table, not a separate banner for each section. Which property should be assigned?

Adding header, footer, and image Medium
A. tableView.tableHeaderView
B. tableView.backgroundView
C. tableView.tableFooterView, followed by reversing the table's coordinate system so the footer appears at the top
D. tableView.sectionHeaderHeight

34 A standard table cell should display a small image beside its text. Which assignment is most direct?

Adding header, footer, and image Medium
A. tableView.image = UIImage(named: "icon")
B. cell.backgroundView = UIImage(named: "icon")
C. cell.textLabel?.layer.contents = "icon"
D. 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?

Adding header, footer, and image Medium
A. tableView(_:viewForHeaderInSection:)
B. tableView(_:accessoryButtonTappedForRowWith:)
C. tableView(_:titleForHeaderInSection:)
D. tableView(_:willSelectRowAt:)

36 A table displays names from people. Which statement correctly obtains the selected person's name inside tableView(_:didSelectRowAt:) for a single-section table?

Displaying item selected Medium
A. let name = people[indexPath.section]
B. let name = people[tableView.numberOfSections]
C. let name = people[indexPath.row + 1], because visible table rows use one-based indexing during selection
D. let name = people[indexPath.row]

37 After showing information about a selected row, an app should immediately remove the row's highlight. Which call is appropriate?

Displaying item selected Medium
A. tableView.reloadRows(at: [indexPath], with: .none)
B. tableView.deselectRow(at: indexPath, animated: true)
C. tableView.deleteRows(at: [indexPath], with: .fade)
D. tableView.setEditing(false, animated: true)

38 A storyboard segue named ShowDetails should run when a row is selected. Which call is appropriate inside didSelectRowAt?

Navigating to another view Medium
A. present("ShowDetails", animated: true)
B. tableView.pushViewController(withIdentifier: "ShowDetails", sender: indexPath)
C. navigationController?.popViewController(animated: true)
D. performSegue(withIdentifier: "ShowDetails", sender: indexPath)

39 Before a segue displays DetailViewController, where should the selected model normally be assigned to the destination controller?

Navigating to another view Medium
A. In tableView(_:heightForRowAt:)
B. In the destination controller's deinit, after the navigation transition has already completed
C. In numberOfSections(in:)
D. In prepare(for:sender:)

40 A table is inside a navigation controller. Which code pushes an already-created detailController onto the navigation stack?

Navigating to another view Medium
A. navigationController?.setViewControllers([], animated: true)
B. navigationController?.present(detailController, completion: true)
C. tableView.pushViewController(detailController, animated: true)
D. navigationController?.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?

Implementing simple table Hard
A. Temporarily clear the table's data source while deleting the model element.
B. Remove the model element first, then delete the row inside performBatchUpdates.
C. Delete the row first, then remove the model element after the animation.
D. Reload the target row first, then remove the model element asynchronously.

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?

Implementing simple table Hard
A. Use one immutable display snapshot for both row count and cell configuration.
B. Read from allItems in cellForRowAt until filtering has fully completed.
C. Return the larger count and show blank cells for unavailable filtered items.
D. Catch out-of-range accesses and call 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?

Customizing TableView cells Hard
A. Increase estimatedRowHeight until every label is visible.
B. Create an unbroken top-to-bottom constraint chain in contentView.
C. Assign a required fixed height constraint to every cell instance.
D. Set the label's frame manually inside cellForRowAt.

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?

Customizing TableView cells Hard
A. Disable cell reuse for rows whose images are downloaded remotely.
B. Cancel prior work and assign the image only if the cell still represents the same item ID.
C. Reload the entire table whenever an individual image download finishes.
D. Compare the cell's current index path with the original numeric row.

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?

Customizing TableView cells Hard
A. Move all item-dependent configuration exclusively into prepareForReuse.
B. Configure every variable property for every item, including default states.
C. Create a new reuse identifier for every possible cell appearance.
D. Configure only nondefault properties and rely on reuse to preserve defaults.

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?

Grouped and indexed sections Hard
A. Return the supplied index without translating it to a section number.
B. Return section 1 because data-section numbering follows the search icon.
C. Return section 0 and place the search UI inside the first data section.
D. Return NSNotFound after separately scrolling or activating the search UI.

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?

Grouped and indexed sections Hard
A. Keep all collation sections, including empty sections, in collation order.
B. Insert one placeholder row into each otherwise empty section.
C. Map every index title to the first currently visible table section.
D. Sort only nonempty sections by their localized display titles.

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?

Grouped and indexed sections Hard
A. Append all item identifiers globally, then assign sections in the data source.
B. Apply an empty snapshot, then mutate its sections after it is displayed.
C. Append section identifiers first, then append each section's item identifiers.
D. Append items first and allow the snapshot to infer their parent sections.

49 A multiline Auto Layout view is assigned to tableView.tableHeaderView, but its height remains incorrect after text changes. Which sequence correctly resizes it?

Adding header, footer, and image Hard
A. Register it as a reusable section header and keep it as tableHeaderView.
B. Call reloadSections and let the table infer the header's intrinsic height.
C. Return its height from tableView(_:heightForHeaderInSection:).
D. Set its fitting width, calculate the fitting height, update its frame, and reassign it.

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?

Adding header, footer, and image Hard
A. Set every reusable visual state explicitly whenever the header is configured.
B. Use a separate header reuse identifier for every section number.
C. Disable header reuse by constructing a new header on every request.
D. Move all section-specific state into 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?

Adding header, footer, and image Hard
A. Recalculate the footer's fitting frame and reassign tableFooterView.
B. Reload the last table row because footer height follows that row's layout.
C. Call reloadSectionIndexTitles to force the footer layout to update.
D. Invalidate the image view and rely on the next scroll event to resize it.

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?

Displaying item selected Hard
A. Store selected item IDs and derive each cell's accessory state during configuration.
B. Store selected index paths permanently and never update them after model changes.
C. Disable reuse for selected cells while continuing to reuse unselected cells.
D. Read the cell's previous accessory state and invert it whenever it reappears.

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?

Displaying item selected Hard
A. Delete and reinsert both items to force new cells to be constructed.
B. Update the selected ID and reconfigure or reload the old and new item identifiers.
C. Mutate the visible cells directly without changing selectedItemID.
D. Create new identifiers for the old and new items before applying a snapshot.

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?

Displaying item selected Hard
A. Disable switch interaction so every touch reaches the table row.
B. Handle the switch action using the represented item ID and update the model.
C. Walk through the switch's superviews until a numeric row can be inferred.
D. Call 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?

Navigating to another view Hard
A. The selected row number converted to a string for later lookup.
B. The selected cell's current visible position in the table.
C. The cell object itself so the destination can read its labels later.
D. The stable item identifier resolved from the current data-source snapshot.

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?

Navigating to another view Hard
A. Use an unwind segue from the table controller to the detail controller.
B. Use a modal segue and manually copy the navigation controller's stack.
C. Use a custom segue that always calls present(_:animated:).
D. Use a show segue and pass the selected model in prepare(for:sender:).

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?

Navigating to another view Hard
A. Add a short delay before calling performSegue in didSelectRowAt.
B. Disable navigation-controller animations for one of the two transitions.
C. Call deselectRow before performing the second navigation transition.
D. Keep one navigation trigger and remove either the cell segue or the manual call.

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?

UITableView basics Hard
A. Use each row's current index path because each visible position is unique.
B. Generate a new random identifier every time a snapshot is applied.
C. Use a persistent unique record ID even when multiple rows have equal content.
D. Use the displayed title as the identifier because the rows look identical.

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?

UITableView basics Hard
A. A matching prototype or prior class/nib registration is required before dequeuing.
B. The identifier becomes registered automatically after the first failed dequeue.
C. The method returns nil, so the caller should construct a fallback cell.
D. The method creates a basic cell automatically when the identifier is unknown.

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?

UITableView basics Hard
A. Mutate visible cells in the background and reload the table on the main actor.
B. Apply snapshots on any queue as long as item identifiers remain unique.
C. Build model values off the main thread, then apply the snapshot on the main actor.
D. Suspend the main thread until the background task has applied the snapshot.