Unit 3: UIKit Controls - Practice Quiz

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

1 Which UIKit control is commonly used to respond to a user's tap?

Implementing UIButton Easy
A. UILabel
B. UISlider
C. UIButton
D. UIImageView

2 Which control is suitable for entering multiple lines of text?

UITextView and keyboard handling Easy
A. UISwitch
B. UIButton
C. UITextView
D. UITextField

3 What method can be used to dismiss the keyboard from a text input control?

UITextView and keyboard handling Easy
A. showKeyboard
B. reloadInputViews
C. becomeFirstResponder
D. resignFirstResponder

4 Which UIKit control is intended for entering a single line of text?

UITextField and customizing inputs Easy
A. UITextView
B. UITextField
C. UIImageView
D. UILabel

5 Which property can hide typed characters in a UITextField for password entry?

UITextField and customizing inputs Easy
A. isSecureTextEntry
B. secureKeyboard
C. isPasswordVisible
D. hidesInputText

6 What type of choice does a UISwitch usually represent?

UISwitch Easy
A. A group of images
B. A binary state
C. A numerical range
D. A text paragraph

7 What is the primary purpose of a UIImageView?

UIImageView Easy
A. Enter text
B. Play a sound
C. Select a date
D. Display an image

8 Which control would be appropriate for a small login form that accepts a username and password?

Creating small application with these controls Easy
A. Two UITextFields
B. Two UIImageViews
C. Two UISliders
D. Two UIProgressViews

9 What does a UIView primarily provide in an iPhone application?

Understanding and working with views Easy
A. A visual rectangular area
B. A network request
C. A sound recording
D. A database connection

10 Which property determines the position and size of a view?

Understanding and working with views Easy
A. image
B. frame
C. title
D. delegate

11 What is a common reason for using multiple view controllers?

Multi-view applications Easy
A. To organize different screens
B. To remove all controls
C. To replace image files
D. To disable navigation

12 What is a segue in a storyboard-based iOS application?

Concept of segue Easy
A. A format for an image
B. A color for a button
C. A transition between view controllers
D. A type of text field

13 Which object manages a stack of view controllers for hierarchical navigation?

Calling another view controller using navigation controller Easy
A. UIImageView
B. UINavigationController
C. UIAlertView
D. UISwitch

14 When passing data to another view controller, where is it commonly assigned before the transition?

Passing and receiving data in view controllers Easy
A. The destination controller
B. The image asset
C. The application icon
D. The keyboard layout

15 What does a UISegmentedControl allow a user to do?

UISegmentedControl Easy
A. Display a photograph
B. Choose among segments
C. View a progress animation
D. Type several paragraphs

16 Which control is commonly used to select a value from a continuous range?

UISlider Easy
A. UILabel
B. UISlider
C. UIImageView
D. UIButton

17 What is the purpose of an alert view?

UIAlertView Easy
A. Enter a long document
B. Display a background image
C. Adjust a numeric slider
D. Show an important message

18 What does an action sheet generally provide?

UIActionSheet Easy
A. A view for image editing
B. A list of possible actions
C. A bar showing download progress
D. A field for password entry

19 What does a progress view communicate to the user?

Progress View Easy
A. The keyboard language
B. The selected image
C. The status of a task
D. The current screen title

20 Which control could be used to let a user turn notifications on or off in a small application?

Creating small application with these controls Easy
A. UIImageView
B. UITextView
C. UISwitch
D. UIProgressView

21 A button is created programmatically, and saveTapped(_:) should run when the user lifts a finger inside the button. Which configuration is correct?

Implementing UIButton Medium
A. button.addGestureRecognizer(#selector(saveTapped(_:)), for: .touchUpInside)
B. button.sendAction(#selector(saveTapped(_:)), to: self, for: .touchUpInside)
C. button.addTarget(self, action: #selector(saveTapped(_:)), for: .touchUpInside)
D. 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?

UITextView and keyboard handling Medium
A. Set the text view's isScrollEnabled property to false
B. Increase the text view's content compression resistance priority
C. Call sizeToFit() whenever the keyboard becomes visible
D. Observe keyboard notifications and adjust the view or scroll-view inset

23 A controller should dismiss the keyboard when the user taps a Done button after editing a UITextView. Which statement is most appropriate?

UITextView and keyboard handling Medium
A. textView.resignFirstResponder()
B. textView.reloadInputViews()
C. textView.setNeedsDisplay()
D. textView.becomeFirstResponder()

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?

UITextField and customizing inputs Medium
A. Set age to .numberPad and password isSecureTextEntry to true
B. Set age to .decimalPad and password clearsOnBeginEditing to true
C. Set age to .phonePad and password adjustsFontSizeToFitWidth to true
D. Set age to .numbersAndPunctuation and password isEnabled to false

25 A text field should reject input that would make its text longer than 10 characters. Where should this rule typically be implemented?

UITextField and customizing inputs Medium
A. In textFieldShouldClear(_:)
B. In textFieldDidBeginEditing(_:)
C. In textFieldShouldBeginEditing(_:)
D. In textField(_:shouldChangeCharactersIn:replacementString:)

26 A settings screen must immediately enable notifications when a UISwitch changes. Which setup is most appropriate?

UISwitch Medium
A. Connect .valueChanged and read the switch's isOn property
B. Connect .touchUpInside and read the switch's isSelected property
C. Connect .editingChanged and read the switch's isEnabled property
D. Connect .primaryActionTriggered and read the switch's isHighlighted 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?

UIImageView Medium
A. .scaleToFill
B. .scaleAspectFit
C. .scaleAspectFill
D. .center

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?

Creating small application with these controls Medium
A. Enable the button after either text input ends editing
B. Recompute button state only when the Save button is tapped
C. Enable the button when the privacy switch is turned on
D. Recompute button state whenever either text input changes

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?

Understanding and working with views Medium
A. translatesAutoresizingMaskIntoConstraints remained true
B. insetsLayoutMarginsFromSafeArea remained true
C. autoresizesSubviews remained true
D. preservesSuperviewLayoutMargins remained false

30 A custom child view must appear above a sibling view without removing either one. Which call directly changes their front-to-back order?

Understanding and working with views Medium
A. parentView.layoutIfNeeded()
B. parentView.bringSubviewToFront(childView)
C. childView.setNeedsLayout()
D. parentView.invalidateIntrinsicContentSize()

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?

Multi-view applications Medium
A. A tab bar controller containing separate navigation controllers
B. A navigation controller containing three alert controllers
C. A split view controller containing three action sheets
D. A page control containing separate presentation controllers

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?

Concept of segue Medium
A. Check segue.destination.title inside viewDidAppear(_:)
B. Check navigationItem.title inside viewWillDisappear(_:)
C. Check sender inside shouldAutorotate
D. Check segue.identifier inside prepare(for:sender:)

33 A view controller is already inside a navigation controller. Which code should open detailsController and add it to the navigation stack?

Calling another view controller using navigation controller Medium
A. navigationController?.pushViewController(detailsController, animated: true)
B. navigationController?.present(detailsController, animated: true)
C. navigationController?.popToViewController(detailsController, animated: true)
D. navigationController?.setToolbarHidden(false, 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?

Passing and receiving data in view controllers Medium
A. Post a memory warning containing the model before the transition
B. Assign the model to a property on the detail controller before pushing
C. Store the model in the detail controller's viewDidDisappear(_:) method
D. Read the model from the navigation bar after pushing the controller

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?

Passing and receiving data in view controllers Medium
A. Search the navigation stack and modify the first controller found
B. Define a delegate protocol and call it when editing finishes
C. Create a second navigation controller for the edited value
D. Assign the previous controller as the edit controller's parent view

36 A segmented control chooses between List, Grid, and Map modes. Which value identifies the user's selected segment?

UISegmentedControl Medium
A. numberOfSegments
B. selectedSegmentIndex
C. currentPage
D. selectedRow

37 A volume slider ranges from 0 to 100, but the application accepts only whole-number values. What should the .valueChanged handler do?

UISlider Medium
A. Set the slider's isContinuous property to false
B. Multiply the slider's maximumValue by 100
C. Convert the slider's minimumValue into a string
D. Round the slider's value before applying it

38 In a legacy application using UIAlertView, the controller must respond when the user selects a button. Which mechanism is used by that API?

UIAlertView Medium
A. Register the alert as the window's first responder
B. Assign an alert delegate and handle the clicked-button callback
C. Add a target for the alert's .editingChanged event
D. Push the alert onto the current navigation stack

39 A legacy UIActionSheet offers Delete, Archive, and Cancel actions. Why should the destructive button be identified correctly when configuring the sheet?

UIActionSheet Medium
A. It moves the destructive action into the navigation bar
B. It automatically performs the deletion without delegate code
C. It receives distinct styling that warns users about a risky action
D. It prevents the action sheet from being dismissed accidentally

40 A download reports 30 completed items out of 120. What value should be assigned to a UIProgressView to represent this state?

Progress View Medium
A. 4.00
B. 0.30
C. 0.40
D. 0.25

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?

Implementing UIButton Hard
A. Recompute all captured index paths only after table-view animations have completed
B. Resolve a stable model identifier through a delegate or closure when the button is tapped
C. Disable cell reuse so each button always retains its original index path
D. Store the row number in the button's 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?

UITextView and keyboard handling Hard
A. Use the keyboard frame's width when the interface is in landscape orientation
B. Use the keyboard frame's height directly because it is already in view coordinates
C. Subtract the keyboard frame's origin from the device's fixed portrait screen height
D. Convert the keyboard frame into the view's coordinates and use its intersection with the view

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?

UITextView and keyboard handling Hard
A. Reset the text view's complete content size whenever the keyboard frame changes
B. Ignore all frame-change notifications after the first keyboard appearance
C. Calculate each inset from a stored baseline instead of adding to the current inset
D. Replace frame-change observation with only 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?

UITextField and customizing inputs Hard
A. Call layoutIfNeeded() on the window containing the active text field
B. Call reloadInputViews() on the text field while it remains first responder
C. Call setNeedsLayout() on the text field's containing view controller
D. Post a synthetic UIResponder.keyboardWillShowNotification notification

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?

UITextField and customizing inputs Hard
A. Return false during composition and manually append each committed replacement
B. Convert every replacement string to ASCII before applying the text-field change
C. Allow marked-text composition and validate after markedTextRange becomes nil
D. Skip final validation whenever the field's 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?

UISwitch Hard
A. Programmatic state changes send .valueChanged only when animation is enabled
B. Programmatic state changes do not automatically send .valueChanged control events
C. Programmatic state changes send events only after the switch enters a window
D. Programmatic state changes send .primaryActionTriggered instead of .valueChanged

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?

UIImageView Hard
A. Use .scaleAspectFit, set a corner radius, and leave clipping disabled
B. Use .scaleAspectFill, set a corner radius, and enable clipping to bounds
C. Use .center, resize the source image, and leave clipping disabled
D. Use .scaleToFill, 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?

Creating small application with these controls Hard
A. Remove all targets during restoration and add separate restoration-only targets
B. Let every control directly modify all other controls whenever its value changes
C. Store state only in the controls and query each control during submission
D. Update one model state and render all controls from that state in one method

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?

Understanding and working with views Hard
A. Recreate the layer during every call to the controller's viewWillAppear
B. Update the layer only when traitCollectionDidChange reports a new style
C. Set the layer frame from UIScreen.main.bounds inside viewDidLoad
D. Create the layer once and update its frame inside viewDidLayoutSubviews

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?

Understanding and working with views Hard
A. Rounded views reject external touches; remove the parent's corner radius before hit testing
B. Buttons outside bounds lose targets; register the same target on the parent view as well
C. Auto Layout disables interaction outside bounds; replace constraints with explicit frames
D. Rendering and hit testing differ; expand or override the parent's 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?

Multi-view applications Hard
A. Add and constrain the child view, then assign the child's navigation controller
B. Call present, move the presented view into the container, then call dismiss
C. Call addChild, add and constrain the child view, then call didMove(toParent:)
D. Add the child view, call addChild, then call willMove(toParent:) manually

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?

Concept of segue Hard
A. shouldPerformSegue runs after prepare(for:sender:), so the destination has already appeared
B. shouldPerformSegue is skipped for programmatically initiated segues, so validation must precede the call
C. performSegue checks validation only when its sender argument is a UIControl
D. 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?

Concept of segue Hard
A. From segue.destination inside the source controller's dismissal callback
B. From the presenting controller returned by the source's navigation controller
C. From the exit placeholder through an outlet stored by the destination controller
D. From 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?

Calling another view controller using navigation controller Hard
A. Push the detail controller using the existing navigation controller
B. Create a second navigation controller and present its root detail controller
C. Replace the navigation controller's root array with the detail controller
D. Present the detail controller modally from the application's window

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?

Passing and receiving data in view controllers Hard
A. Use a weak delegate or a closure that captures the receiving controller weakly
B. Give the detail controller a strong reference to the list controller and assign its properties
C. Create a new list controller with the value and replace the navigation stack
D. Store the edited value in a global variable and read it in every viewDidAppear

56 A UISegmentedControl is configured with isMomentary = true for toolbar-like commands. Which behavior should application logic expect?

UISegmentedControl Hard
A. The tapped segment sends an event but does not remain visually selected
B. Every segment independently toggles between selected and unselected states
C. The first segment remains selected until another segment is tapped
D. The control suppresses .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?

UISlider Hard
A.
B.
C.
D.

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?

UIAlertView Hard
A. Continue using UIAlertView but compare each action's displayed title by identity
B. Use UIAlertController with distinct UIAlertAction handlers for each action
C. Use a plain modal view controller and infer the selected action from its dismissal
D. Use UIActionSheet and assign integer tags to all localized button titles

59 An action-sheet-style UIAlertController works on iPhone but crashes when presented on iPad. What configuration is commonly missing?

UIActionSheet Hard
A. A cancel action whose title exactly matches the operating system's locale
B. A valid popoverPresentationController source view, source rectangle, or bar button item
C. A navigation-controller delegate that approves the action sheet's presentation
D. A custom transition coordinator attached to the presenting view controller

60 A download callback reports completedBytes and totalBytes on a background queue. A UIProgressView must show accurate determinate progress. Which update is correct?

Progress View Hard
A. Assign the completed byte count directly because the progress view normalizes integer values
B. Assign Float(completedBytes / totalBytes) directly on the callback queue for lower latency
C. Assign Float(completedBytes) / Float(totalBytes) on the main queue after verifying totalBytes > 0
D. Assign Float(totalBytes) / Float(completedBytes) on the main queue and clamp values above one