Unit 3: UIKit Controls - Practice Quiz
1 Which UIKit control is commonly used to respond to a user's tap?
2 Which control is suitable for entering multiple lines of text?
3 What method can be used to dismiss the keyboard from a text input control?
4 Which UIKit control is intended for entering a single line of text?
5
Which property can hide typed characters in a UITextField for password entry?
6
What type of choice does a UISwitch usually represent?
7
What is the primary purpose of a UIImageView?
8 Which control would be appropriate for a small login form that accepts a username and password?
9
What does a UIView primarily provide in an iPhone application?
10 Which property determines the position and size of a view?
11 What is a common reason for using multiple view controllers?
12 What is a segue in a storyboard-based iOS application?
13 Which object manages a stack of view controllers for hierarchical navigation?
14 When passing data to another view controller, where is it commonly assigned before the transition?
15
What does a UISegmentedControl allow a user to do?
16 Which control is commonly used to select a value from a continuous range?
17 What is the purpose of an alert view?
18 What does an action sheet generally provide?
19 What does a progress view communicate to the user?
20 Which control could be used to let a user turn notifications on or off in a small application?
21
A button is created programmatically, and saveTapped(_:) should run when the user lifts a finger inside the button. Which configuration is correct?
button.addGestureRecognizer(#selector(saveTapped(_:)), for: .touchUpInside)
button.addTarget(self, action: #selector(saveTapped(_:)), for: .touchUpInside)
button.sendAction(#selector(saveTapped(_:)), to: self, for: .touchUpInside)
button.addTarget(self, action: #selector(saveTapped(_:)), for: .touchDown)
22
A UITextView near the bottom of a screen is hidden by the keyboard. Which approach most directly keeps the active text area visible?
isScrollEnabled property to false
sizeToFit() whenever the keyboard becomes visible
23
A controller should dismiss the keyboard when the user taps a Done button after editing a UITextView. Which statement is most appropriate?
textView.reloadInputViews()
textView.resignFirstResponder()
textView.becomeFirstResponder()
textView.setNeedsDisplay()
24 A form requires a numeric keyboard for an age field and should hide the entered characters for a password field. Which configuration is correct?
.numberPad and password isSecureTextEntry to true
.decimalPad and password clearsOnBeginEditing to true
.numbersAndPunctuation and password isEnabled to false
.phonePad and password adjustsFontSizeToFitWidth to true
25 A text field should reject input that would make its text longer than 10 characters. Where should this rule typically be implemented?
textFieldDidBeginEditing(_:)
textField(_:shouldChangeCharactersIn:replacementString:)
textFieldShouldBeginEditing(_:)
textFieldShouldClear(_:)
26
A settings screen must immediately enable notifications when a UISwitch changes. Which setup is most appropriate?
.primaryActionTriggered and read the switch's isHighlighted property
.editingChanged and read the switch's isEnabled property
.touchUpInside and read the switch's isSelected property
.valueChanged and read the switch's isOn property
27 A profile image must fill a fixed square image view without distortion, and excess portions may be cropped. Which content mode should be used?
.center
.scaleAspectFill
.scaleAspectFit
.scaleToFill
28 A small profile form contains a name field, biography text view, privacy switch, and Save button. The Save button should remain disabled until both text inputs contain non-whitespace text. What is the best design?
29 A subview created in code ignores its Auto Layout constraints and continues using its frame-based size. Which property was most likely left incorrectly configured?
preservesSuperviewLayoutMargins remained false
autoresizesSubviews remained true
insetsLayoutMarginsFromSafeArea remained true
translatesAutoresizingMaskIntoConstraints remained true
30 A custom child view must appear above a sibling view without removing either one. Which call directly changes their front-to-back order?
parentView.bringSubviewToFront(childView)
parentView.invalidateIntrinsicContentSize()
parentView.layoutIfNeeded()
childView.setNeedsLayout()
31 A multi-view application switches between three independent top-level sections, and each section should preserve its own navigation state. Which structure best fits this requirement?
32
Two segues leave the same view controller. Before navigation, the controller must configure the destination only for the segue whose identifier is showDetails. What should it do?
segue.destination.title inside viewDidAppear(_:)
navigationItem.title inside viewWillDisappear(_:)
segue.identifier inside prepare(for:sender:)
sender inside shouldAutorotate
33
A view controller is already inside a navigation controller. Which code should open detailsController and add it to the navigation stack?
navigationController?.present(detailsController, animated: true)
navigationController?.popToViewController(detailsController, animated: true)
navigationController?.setToolbarHidden(false, animated: true)
navigationController?.pushViewController(detailsController, animated: true)
34 A list controller pushes a detail controller and needs to pass the selected model before the detail screen appears. Which technique is most direct?
viewDidDisappear(_:) method
35 An edit controller must send a changed value back to the previous controller without tightly coupling itself to that controller's class. Which pattern is appropriate?
36 A segmented control chooses between List, Grid, and Map modes. Which value identifies the user's selected segment?
currentPage
selectedSegmentIndex
selectedRow
numberOfSegments
37
A volume slider ranges from 0 to 100, but the application accepts only whole-number values. What should the .valueChanged handler do?
minimumValue into a string
isContinuous property to false
value before applying it
maximumValue by 100
38
In a legacy application using UIAlertView, the controller must respond when the user selects a button. Which mechanism is used by that API?
.editingChanged event
39
A legacy UIActionSheet offers Delete, Archive, and Cancel actions. Why should the destructive button be identified correctly when configuring the sheet?
40
A download reports 30 completed items out of 120. What value should be assigned to a UIProgressView to represent this state?
4.00
0.25
0.40
0.30
41
A UIButton inside a reusable table-view cell uses an action closure that captures the cell's original indexPath. After rows are inserted, tapping the button updates the wrong model object. Which redesign is most robust?
tag whenever the cell becomes visible
42
A text view must remain visible above floating, split, and docked keyboards. A keyboard notification supplies keyboardFrameEndUserInfoKey. Which calculation is the safest basis for the text view's bottom inset?
43
A controller adds the keyboard overlap to textView.contentInset.bottom every time keyboardWillChangeFrame is received. After several keyboard transitions, the inset becomes excessively large. What is the correct fix?
keyboardDidShow and keyboardDidHide
44
A visible, first-responder UITextField has its inputView changed from the system keyboard to a custom picker, but the old keyboard remains displayed. Which operation should follow the assignment?
layoutIfNeeded() on the window containing the active text field
setNeedsLayout() on the text field's containing view controller
UIResponder.keyboardWillShowNotification notification
reloadInputViews() on the text field while it remains first responder
45 A text-field delegate rejects any proposed replacement that is not ASCII. Users of Chinese and Japanese keyboards can no longer enter text correctly. Which adjustment best preserves validation and input-method composition?
markedTextRange becomes nil
false during composition and manually append each committed replacement
selectedTextRange is non-nil
46
A controller restores a UISwitch with setOn(savedValue, animated: false), but its .valueChanged handler does not update dependent controls. What behavior should the developer rely on?
.primaryActionTriggered instead of .valueChanged
.valueChanged only when animation is enabled
.valueChanged control events
47 An image must fill an image view without distortion, may crop equally as needed, and must never draw outside the view's rounded bounds. Which configuration satisfies all requirements?
.scaleToFill, set a corner radius, and enable clipping to bounds
.scaleAspectFit, set a corner radius, and leave clipping disabled
.center, resize the source image, and leave clipping disabled
.scaleAspectFill, set a corner radius, and enable clipping to bounds
48 A form contains a text field, switch, slider, image view, and submit button. Restoring saved values sometimes produces inconsistent UI because target-action handlers execute overlapping update logic. Which architecture best prevents this?
49
A gradient layer is created for a view in viewDidLoad using the view's current bounds. After Auto Layout and rotation, the gradient has the wrong size. Which lifecycle strategy is most reliable?
traitCollectionDidChange reports a new style
viewWillAppear
viewDidLayoutSubviews
UIScreen.main.bounds inside viewDidLoad
50
A button extends outside its parent's bounds. It is visible because clipsToBounds is false, but taps on the extended portion are ignored. What explains this behavior and provides a suitable remedy?
point(inside:with:) behavior
51 A view controller permanently embeds another view controller's view inside a container. Which sequence correctly establishes UIKit view-controller containment?
addChild, add and constrain the child view, then call didMove(toParent:)
addChild, then call willMove(toParent:) manually
present, move the presented view into the container, then call dismiss
52
Validation is implemented only in shouldPerformSegue(withIdentifier:sender:). The segue is later initiated by calling performSegue(withIdentifier:sender:), and invalid data unexpectedly passes through. Why?
shouldPerformSegue is skipped for programmatically initiated segues, so validation must precede the call
shouldPerformSegue runs after prepare(for:sender:), so the destination has already appeared
performSegue checks validation only when its sender argument is a UIControl
shouldPerformSegue is evaluated only for unwind segues connected to an exit object
53 During an unwind segue, the destination controller needs a value from the controller being dismissed. Where should the destination obtain that value?
segue.destination inside the source controller's dismissal callback
segue.source inside the destination controller's unwind action
54 A list controller inside a navigation controller must open a detail controller so that the standard Back button returns to the same list instance. Which transition is appropriate?
55 A detail controller must send an edited value back to its list controller before being popped. The detail controller may outlive asynchronous work, so retain cycles must be avoided. Which design is most appropriate?
viewDidAppear
56
A UISegmentedControl is configured with isMomentary = true for toolbar-like commands. Which behavior should application logic expect?
.valueChanged and sends only touch-down events
57 A slider value ranges from to and must control a frequency logarithmically from to , where . Which mapping gives equal slider distances to equal multiplicative frequency changes?
58
Legacy code uses UIAlertView delegates and identifies actions by comparing localized button titles. During modernization, which replacement is both safer and aligned with current UIKit?
UIAlertController with distinct UIAlertAction handlers for each action
UIActionSheet and assign integer tags to all localized button titles
UIAlertView but compare each action's displayed title by identity
59
An action-sheet-style UIAlertController works on iPhone but crashes when presented on iPad. What configuration is commonly missing?
popoverPresentationController source view, source rectangle, or bar button item
60
A download callback reports completedBytes and totalBytes on a background queue. A UIProgressView must show accurate determinate progress. Which update is correct?
Float(completedBytes) / Float(totalBytes) on the main queue after verifying totalBytes > 0
Float(totalBytes) / Float(completedBytes) on the main queue and clamp values above one
Float(completedBytes / totalBytes) directly on the callback queue for lower latency
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 →