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. UIImageView
B. UILabel
C. UISlider
D. UIButton

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

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

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. UIImageView
B. UITextView
C. UITextField
D. UILabel

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

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

6 What type of choice does a UISwitch usually represent?

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

7 What is the primary purpose of a UIImageView?

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

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 UISliders
C. Two UIProgressViews
D. Two UIImageViews

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

Understanding and working with views Easy
A. A sound recording
B. A network request
C. A visual rectangular area
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. delegate
D. title

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

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

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

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

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

Calling another view controller using navigation controller Easy
A. UIImageView
B. UIAlertView
C. UINavigationController
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 image asset
B. The destination controller
C. The keyboard layout
D. The application icon

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. UIButton
B. UILabel
C. UISlider
D. UIImageView

17 What is the purpose of an alert view?

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

18 What does an action sheet generally provide?

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

19 What does a progress view communicate to the user?

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

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. UISwitch
B. UITextView
C. UIImageView
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.addTarget(self, action: #selector(saveTapped(_:)), for: .touchUpInside)
C. button.sendAction(#selector(saveTapped(_:)), to: self, 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.reloadInputViews()
B. textView.resignFirstResponder()
C. textView.becomeFirstResponder()
D. 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?

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 .numbersAndPunctuation and password isEnabled to false
D. Set age to .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?

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

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

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

UIImageView Medium
A. .center
B. .scaleAspectFill
C. .scaleAspectFit
D. .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?

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

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. preservesSuperviewLayoutMargins remained false
B. autoresizesSubviews remained true
C. insetsLayoutMarginsFromSafeArea remained true
D. 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?

Understanding and working with views Medium
A. parentView.bringSubviewToFront(childView)
B. parentView.invalidateIntrinsicContentSize()
C. parentView.layoutIfNeeded()
D. 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?

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

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 segue.identifier inside prepare(for:sender:)
D. Check 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?

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

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

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. Create a second navigation controller for the edited value
B. Search the navigation stack and modify the first controller found
C. Assign the previous controller as the edit controller's parent view
D. Define a delegate protocol and call it when editing finishes

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

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

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. Convert the slider's minimumValue into a string
B. Set the slider's isContinuous property to false
C. Round the slider's value before applying it
D. Multiply the slider's 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?

UIAlertView Medium
A. Assign an alert delegate and handle the clicked-button callback
B. Register the alert as the window's first responder
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 receives distinct styling that warns users about a risky action
B. It automatically performs the deletion without delegate code
C. It prevents the action sheet from being dismissed accidentally
D. It moves the destructive action into the navigation bar

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.25
C. 0.40
D. 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?

Implementing UIButton Hard
A. Disable cell reuse so each button always retains its original index path
B. Resolve a stable model identifier through a delegate or closure when the button is tapped
C. Recompute all captured index paths only after table-view animations have completed
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. Subtract the keyboard frame's origin from the device's fixed portrait screen height
B. Use the keyboard frame's width when the interface is in landscape orientation
C. Use the keyboard frame's height directly because it is already in view coordinates
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. Ignore all frame-change notifications after the first keyboard appearance
B. Replace frame-change observation with only keyboardDidShow and keyboardDidHide
C. Reset the text view's complete content size whenever the keyboard frame changes
D. Calculate each inset from a stored baseline instead of adding to the current inset

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 setNeedsLayout() on the text field's containing view controller
C. Post a synthetic UIResponder.keyboardWillShowNotification notification
D. Call 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?

UITextField and customizing inputs Hard
A. Allow marked-text composition and validate after markedTextRange becomes nil
B. Return false during composition and manually append each committed replacement
C. Convert every replacement string to ASCII before applying the text-field change
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 .primaryActionTriggered instead of .valueChanged
B. Programmatic state changes send .valueChanged only when animation is enabled
C. Programmatic state changes do not automatically send .valueChanged control events
D. Programmatic state changes send events only after the switch enters a window

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

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. Update the layer only when traitCollectionDidChange reports a new style
B. Recreate the layer during every call to the controller's viewWillAppear
C. Create the layer once and update its frame inside viewDidLayoutSubviews
D. Set the layer frame from 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?

Understanding and working with views Hard
A. Buttons outside bounds lose targets; register the same target on the parent view as well
B. Rendering and hit testing differ; expand or override the parent's point(inside:with:) behavior
C. Auto Layout disables interaction outside bounds; replace constraints with explicit frames
D. Rounded views reject external touches; remove the parent's corner radius before hit testing

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. Call addChild, add and constrain the child view, then call didMove(toParent:)
B. Add the child view, call addChild, then call willMove(toParent:) manually
C. Add and constrain the child view, then assign the child's navigation controller
D. Call 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?

Concept of segue Hard
A. shouldPerformSegue is skipped for programmatically initiated segues, so validation must precede the call
B. shouldPerformSegue runs after prepare(for:sender:), so the destination has already appeared
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 the exit placeholder through an outlet stored by the destination controller
B. From the presenting controller returned by the source's navigation controller
C. From segue.destination inside the source controller's dismissal callback
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. Create a second navigation controller and present its root detail controller
B. Replace the navigation controller's root array with the detail controller
C. Push the detail controller using the existing navigation 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. Store the edited value in a global variable and read it in every viewDidAppear
C. Create a new list controller with the value and replace the navigation stack
D. Give the detail controller a strong reference to the list controller and assign its properties

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

UISegmentedControl Hard
A. The first segment remains selected until another segment is tapped
B. The control suppresses .valueChanged and sends only touch-down events
C. The tapped segment sends an event but does not remain visually selected
D. Every segment independently toggles between selected and unselected states

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

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

UIActionSheet Hard
A. A custom transition coordinator attached to the presenting view controller
B. A cancel action whose title exactly matches the operating system's locale
C. A navigation-controller delegate that approves the action sheet's presentation
D. A valid 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?

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