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. UITabBarItem
B. UITableView
C. UINavigationBar
D. UICollectionViewCell

2 Which protocol supplies row content to a UITableView?

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

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

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

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

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

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

Implementing simple table Easy
A. tableView(_:canEditRowAt:)
B. tableView(_:viewForFooterInSection:)
C. tableView(_:cellForRowAt:)
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 select multiple cells
D. To reuse existing 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 selected section titles
B. To identify navigation destinations
C. To identify reusable cell types
D. To identify table view controllers

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

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

10 Which table view style visually separates rows into groups?

Grouped and indexed sections Easy
A. Overlay
B. Compact
C. Grouped
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 width and height
D. A title and subtitle

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

Grouped and indexed sections Easy
A. numberOfSections(in:)
B. sectionIndexTitles(for:)
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. tableHeaderView
B. contentInset
C. sectionHeaderHeight
D. tableFooterView

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

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

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

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

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

Displaying item selected Easy
A. tableView(_:cellForRowAt:)
B. tableView(_:didSelectRowAt:)
C. tableView(_:numberOfRowsInSection:)
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 cell reuse count
B. Use the table frame width
C. Use the row from IndexPath
D. Use the section header height

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

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

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

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

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

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

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. tableView(_:numberOfRowsInSection:) and tableView(_:cellForRowAt:)
C. numberOfSections(in:) and tableView(_:viewForHeaderInSection:)
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 cities[indexPath.row].count
B. return cities.count - 1
C. return tableView.numberOfSections
D. return cities.count

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

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

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 table view must use the grouped presentation style
D. The view controller must implement every optional method from both the data source and delegate protocols

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

Customizing TableView cells Medium
A. Create a new base UITableViewCell
B. Cast the table view to ProductCell
C. Convert the row index into a cell identifier and reconnect every outlet programmatically
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. Disable cell reuse by assigning a unique identifier to every row
B. Reload the entire table whenever an image request completes
C. Move all image-loading code into numberOfRowsInSection
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. Set the row height to zero and remove the bottom constraint
B. Use a fixed row height and increase the table view's content inset whenever a long description is encountered
C. Use automaticDimension and provide complete vertical constraints
D. Calculate the height only in 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?

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.row + indexPath.section]
B. itemsBySection.first?[indexPath.section + indexPath.row]
C. itemsBySection[indexPath.row][indexPath.section]
D. 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?

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

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

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

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

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

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.sectionHeaderHeight
B. tableView.tableHeaderView
C. tableView.backgroundView
D. 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?

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

Displaying item selected Medium
A. let name = people[tableView.numberOfSections]
B. let name = people[indexPath.row]
C. let name = people[indexPath.row + 1], because visible table rows use one-based indexing during selection
D. 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?

Displaying item selected Medium
A. tableView.setEditing(false, animated: true)
B. tableView.reloadRows(at: [indexPath], with: .none)
C. tableView.deselectRow(at: indexPath, animated: true)
D. 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?

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

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 numberOfSections(in:)
B. In prepare(for:sender:)
C. In the destination controller's deinit, after the navigation transition has already completed
D. In tableView(_:heightForRowAt:)

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?.pushViewController(detailController, animated: true)
C. navigationController?.present(detailController, completion: true)
D. 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?

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

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. Read from allItems in cellForRowAt until filtering has fully completed.
B. Use one immutable display snapshot for both row count and cell configuration.
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. Set the label's frame manually inside cellForRowAt.
C. Assign a required fixed height constraint to every cell instance.
D. Create an unbroken top-to-bottom constraint chain in 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?

Customizing TableView cells Hard
A. Cancel prior work and assign the image only if the cell still represents the same item ID.
B. Reload the entire table whenever an individual image download finishes.
C. Disable cell reuse for rows whose images are downloaded remotely.
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. Configure only nondefault properties and rely on reuse to preserve defaults.
B. Create a new reuse identifier for every possible cell appearance.
C. Configure every variable property for every item, including default states.
D. Move all item-dependent configuration exclusively into 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?

Grouped and indexed sections Hard
A. Return NSNotFound after separately scrolling or activating the search UI.
B. Return the supplied index without translating it to a section number.
C. Return section 0 and place the search UI inside the first data section.
D. Return 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?

Grouped and indexed sections Hard
A. Keep all collation sections, including empty sections, in collation order.
B. Map every index title to the first currently visible table section.
C. Insert one placeholder row into each otherwise empty 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 section identifiers first, then append each section's item identifiers.
B. Append all item identifiers globally, then assign sections in the data source.
C. Append items first and allow the snapshot to infer their parent sections.
D. Apply an empty snapshot, then mutate its sections after it is displayed.

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. Call reloadSections and let the table infer the header's intrinsic height.
B. Register it as a reusable section header and keep it as tableHeaderView.
C. Set its fitting width, calculate the fitting height, update its frame, and reassign it.
D. Return its height from 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?

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

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. Invalidate the image view and rely on the next scroll event to resize it.
D. Call 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?

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

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. Mutate the visible cells directly without changing selectedItemID.
B. Update the selected ID and reconfigure or reload the old and new item identifiers.
C. Delete and reinsert both items to force new cells to be constructed.
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. Call didSelectRowAt directly from the switch's value-change handler.
C. Walk through the switch's superviews until a numeric row can be inferred.
D. Handle the switch action using the represented item ID and update the model.

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 stable item identifier resolved from the current data-source snapshot.
B. The selected cell's current visible position in the table.
C. The selected row number converted to a string for later lookup.
D. The cell object itself so the destination can read its labels later.

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 a modal segue and manually copy the navigation controller's stack.
B. Use a show segue and pass the selected model in prepare(for:sender:).
C. Use an unwind segue from the table controller to the detail controller.
D. Use a custom segue that always calls 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?

Navigating to another view Hard
A. Call deselectRow before performing the second navigation transition.
B. Add a short delay before calling performSegue in didSelectRowAt.
C. Disable navigation-controller animations for one of the two transitions.
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. Use a persistent unique record ID even when multiple rows have equal content.
C. Use the displayed title as the identifier because the rows look identical.
D. Generate a new random identifier every time a snapshot is applied.

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. The method creates a basic cell automatically when the identifier is unknown.
B. A matching prototype or prior class/nib registration is required before dequeuing.
C. The method returns nil, so the caller should construct a fallback cell.
D. The identifier becomes registered automatically after the first failed dequeue.

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. Apply snapshots on any queue as long as item identifiers remain unique.
B. Mutate visible cells in the background and reload the table on the main actor.
C. Suspend the main thread until the background task has applied the snapshot.
D. Build model values off the main thread, then apply the snapshot on the main actor.