Unit 5: iPhone Project Templates - Practice Quiz
1
What is the main purpose of a UINavigationController in an iPhone application?
2 Which operation displays a new view controller on a navigation stack?
3 What usually happens when the Back button is tapped in a navigation controller?
4 What does Auto Layout use to determine the position and size of interface elements?
5 What is a major benefit of using Auto Layout?
6 Which constraint controls the horizontal distance between two views?
7 Which class is commonly used to play a local audio file in an iOS application?
UICollectionView
AVAudioPlayer
UINavigationItem
UITabBarController
8 Which framework provides common classes for audio and video playback in iOS?
MapKit
Contacts
AVFoundation
CoreLocation
9 Which class can be used to play both local and streamed media?
AVPlayer
UILabel
UISlider
UITableViewCell
10
What is the primary use of a UICollectionView?
11 What is an individual item in a collection view usually represented by?
UITabBarItem
UINavigationBar
UICollectionViewCell
AVPlayerItem
12 Which object provides the data displayed by a collection view?
13
What is the main purpose of a UIToolbar?
14
Which objects are commonly placed inside a UIToolbar?
UINavigationController objects
AVAudioPlayer objects
UIBarButtonItem objects
UICollectionViewCell objects
15 What is the purpose of a tab bar in an iPhone application?
16 Which controller is commonly used to manage a tab-based interface?
UITabBarController
UIImagePickerController
UIAlertController
UISplitViewController
17 What happens when a user selects a different tab bar item?
18 What type of database is SQLite?
19 Which SQL command is used to retrieve records from an SQLite table?
UPDATE
INSERT
SELECT
DELETE
20 Which SQL command adds a new record to an SQLite table?
UPDATE
DROP
INSERT
SELECT
21 A view controller must open a detail screen and display a Back button automatically. Which approach should be used?
pushViewController(_:animated:)
present(_:animated:)
22 An application has pushed three view controllers: Home, Products, and Details. Which call returns directly from Details to Home?
popViewController(animated:)
setViewControllers([], animated:)
popToRootViewController(animated:)
dismiss(animated:completion:)
23
A navigation controller should begin with HomeViewController as its first screen. Which initialization is appropriate?
UINavigationController(rootViewController: homeController)
UINavigationController(navigationBarClass: nil, toolbarClass: nil)
UINavigationController(coder: homeController)
UINavigationController(nibName: "Home", bundle: nil)
24 A button must remain 20 points from the trailing edge of its container in both portrait and landscape orientations. Which constraint best achieves this?
button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)
button.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 20)
button.widthAnchor.constraint(equalToConstant: 20)
25 A label with variable text should expand horizontally before a nearby button is compressed. Which Auto Layout setting should be adjusted?
26 A programmatically created view ignores its anchor constraints and keeps an autoresizing-mask-based frame. What change is required?
isUserInteractionEnabled to true
translatesAutoresizingMaskIntoConstraints to false
clipsToBounds to true
autoresizesSubviews to false
27 An application needs to play a short local audio file and provide direct controls for play, pause, and volume. Which class is most appropriate?
MPMediaPickerController
AVAudioPlayer
AVCaptureSession
AVPlayerViewController
28
A developer creates an AVAudioPlayer for a local file, but no sound is produced because playback was never initialized. Which sequence should be used?
seek(to:) and then present()
loadView() and then resume()
prepareToPlay() and then play()
startRunning() and then play()
29 An application must stream a remote video and display standard playback controls. Which combination is appropriate?
AVCaptureDevice with UIToolbar
MPMediaPickerController with WKWebView
AVPlayer with AVPlayerViewController
AVAudioPlayer with UIImageView
30 A collection view cell appears with old content while scrolling because cells are reused. Where should the cell's labels and images normally be assigned?
collectionView(_:didSelectItemAt:)
collectionView(_:layout:sizeForItemAt:)
collectionView(_:cellForItemAt:)
collectionView(_:numberOfItemsInSection:)
31 After inserting an item into a collection view's data source, which update correctly keeps the interface synchronized?
reloadSections([])
reloadInputViews(), then insert the model item
setNeedsLayout(), then delete the old model item
insertItems(at:)
32
A collection view uses UICollectionViewFlowLayout. Which delegate method can provide a different size for each item?
collectionView(_:willDisplay:forItemAt:)
collectionView(_:layout:sizeForItemAt:)
collectionView(_:shouldSelectItemAt:)
collectionView(_:didHighlightItemAt:)
33 A toolbar needs Save aligned left and Delete aligned right. Which item should be placed between the two buttons?
34
A UIToolbar has been created programmatically with three bar button items. Which property should receive those items?
toolbar.items
toolbar.gestureRecognizers
toolbar.subviews
toolbar.constraints
35 An application has Home, Search, and Settings sections, each requiring its own navigation history. What hierarchy is most appropriate?
36
A developer wants the Settings tab to be selected when the application first displays its three tabs. Which property should be set to 2?
selectedItem
currentPage
selectionStyle
selectedIndex
37 Which configuration adds a visible title and system icon to a view controller displayed by a tab bar controller?
UINavigationBar to view
UITabBarItem to tabBarItem
UIBarButtonItem to navigationItem
UIToolbar to inputView
38 A query must find a user by an email address supplied through a text field. Which approach best reduces the risk of SQL injection?
39 Several related SQLite updates must either all succeed or all be undone. Which SQL commands should surround the updates?
ATTACH DATABASE and DETACH DATABASE
SELECT and ORDER BY
CREATE TABLE and DROP TABLE
BEGIN TRANSACTION and COMMIT
40
An SQLite query has been prepared with sqlite3_prepare_v2. Which return value from sqlite3_step indicates that a row of result data is available?
SQLITE_ROW
SQLITE_BUSY
SQLITE_OK
SQLITE_DONE
41
A view controller pushed onto a UINavigationController needs to animate a custom subview alongside both interactive and noninteractive pop transitions. Which approach correctly keeps the animation synchronized and handles cancellation?
UINavigationController.didShow notifications and compare the navigation stack afterward
transitionCoordinator and inspect the completion context
navigationController(_:willShow:animated:) and use a fixed-duration property animator
viewWillDisappear(_:) and reverse it in viewDidAppear(_:)
42
After assigning a custom object as a navigation controller's interactivePopGestureRecognizer.delegate, the edge-swipe gesture intermittently stops working. What is the most robust correction?
popViewController(animated:) after the user's finger crosses half the screen, while disabling the original recognizer
viewDidAppear(_:) executes
nil after the root controller appears
43
A navigation controller is restoring a deep stack [A, B, C] without animation. The current stack is [A, X]. Which operation replaces the entire stack atomically while preserving normal containment callbacks?
[A, B, C] directly to the navigation controller's children property
B, present C, and dismiss X after the final presentation completes
setViewControllers([A, B, C], animated: false)
popToRootViewController(animated: false) followed by two pushes
44 A horizontal stack contains a label and a text field. Both have enough constraints to determine their positions. When space becomes limited, the label must remain at intrinsic width and the text field should shrink first. Which priority change directly expresses this rule?
45
A scroll view fills its parent. Its content view is constrained on all four edges to contentLayoutGuide and has equal width to frameLayoutGuide. The content view has no explicit height, but its vertically arranged subviews form an unbroken top-to-bottom constraint chain. What behavior results?
contentSize is assigned manually after Auto Layout finishes
46
A view's horizontal position and width are fully determined, but its vertical constraints specify only a fixed height and centerY. Interface Builder still reports an ambiguous layout at runtime. Which statement is correct?
47 A spoken-audio app should pause when an interruption begins and resume only if playback was active beforehand and the interruption options indicate that resumption is appropriate. Which design is correct?
.began and recreate the AVPlayer whenever .ended arrives
AVPlayer automatically restores the user's exact playback intent
.began, and conditionally resume on .ended with .shouldResume
.began and always call play() on .ended, regardless of the prior state
48
An app loops a local video by observing AVPlayerItem.didPlayToEndTimeNotification. It later replaces player.currentItem, but looping stops. What is the most likely cause?
AVPlayerLayer before end notifications can be posted
AVPlayer instance, so a second player is required
actionAtItemEnd automatically changed to .pause during item replacement
49 A music app must continue playing when the screen locks and should mix with audio from another app at a reduced relative volume. Which audio-session configuration best matches the requirement?
.ambient with .duckOthers, without enabling a background mode
.soloAmbient with .mixWithOthers, plus the Location background mode
.playback with .mixWithOthers, plus the Audio background mode
.record with .defaultToSpeaker, plus the Audio background mode
50
A collection view currently displays 5 items. Inside performBatchUpdates, the code deletes item 1 and inserts a new item at index 4. What must the data source report when UIKit validates the completed update?
51 A diffable data source snapshot contains two visually identical messages with the same database identifier. Applying it raises an exception. What is the correct model-level fix?
52 A self-sizing collection-view cell uses Auto Layout, but its height stays at the estimated value even though multiline text needs more space. Which condition is essential inside the cell?
draw(_:) and update its frame from the text's bounding rectangle
sizeToFit() on every visible cell after each layout pass
53 A toolbar contains flexible space between two leading actions and one trailing action. When the toolbar width changes, which item absorbs the extra horizontal space?
UIBarButtonItem created with the .fixedSpace system item
UIBarButtonItem created with the .flexibleSpace system item
54 A screen is inside a navigation controller whose built-in toolbar is used. The toolbar must show items specific to the visible child controller and update correctly during pushes and pops. Where should those items be configured?
setToolbarItems(_:animated:)
navigationController?.toolbar?.items from the application delegate
addSubview(_:)
UIToolbar added over the navigation controller's built-in toolbar so each child can manage its own independent bar
55
A UITabBarController has five child controllers. The user selects the fifth tab, which appears under the system-generated More interface. Which value should application logic use to identify the selected child reliably?
selectedViewController, compared with the controller's stable application identity
selectedIndex, assumed to equal the visible position within the More table
56 Each tab contains its own navigation controller. After switching tabs, the app unexpectedly resets the previously selected tab to its root screen. Which architecture preserves independent navigation history?
didSelect is called
viewControllers
viewWillDisappear(_:) to synchronize tab state
57 The current tab should remain selected when a user taps its tab bar item again, but the tab's navigation stack should pop to root. Which delegate decision is best suited to initiate this behavior?
tabBarController(_:didSelect:) after creating a replacement tab controller
selectedIndex to zero in viewDidDisappear(_:) of the current navigation controller
viewControllers array
tabBarController(_:shouldSelect:), pop the current stack, and return false
58 An SQLite table stores bank balances. A transfer performs one debit and one credit. The process must never commit only one of them, including when the credit violates a constraint. Which sequence provides the required atomicity?
59
A prepared SQLite query uses WHERE nickname = ?. The application binds SQL NULL because the user has no nickname, but rows whose nickname is NULL are not returned. Why?
NOT NULL
VACUUM so null entries become visible to indexed comparisons
NULL to an empty string before evaluating equality
NULL are unknown; the query must use IS NULL for that case
60
Multiple background tasks share one SQLite connection opened with serialized threading support. Statements are protected by a serial queue, but a result row's text pointer is stored and read after sqlite3_step is called again. What is the defect?
sqlite3_step automatically converts text storage to UTF-16 and invalidates only numeric columns
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 →