UIKit Essentials: Views, ViewControllers u0026 Navigation Quiz Quiz

Explore core concepts of UIKit with this quiz focused on views, view controllers, and navigation fundamentals. Check your understanding of user interface structure, hierarchy management, navigation patterns, and UIKit basics essential for building intuitive mobile applications.

  1. UIView Hierarchy

    Which method should you use to add a subview to an existing UIView in UIKit?

    1. insertSubviewAbove()
    2. removeFromSuperview()
    3. addSubview()
    4. appendChild()

    Explanation: addSubview() is the correct method to add a child view to an existing view, making it appear within the parent view's hierarchy. insertSubviewAbove() is used for a more specific case when you want to insert a view above another sibling. removeFromSuperview() is for removing a view from its parent. appendChild() is not a UIKit method; it is unrelated in this context.

  2. ViewController Basics

    What is the primary role of a ViewController in the UIKit architecture?

    1. Handling low-level touch events exclusively
    2. Managing the content and interactions of a screen
    3. Storing data persistently
    4. Drawing graphics on the screen

    Explanation: ViewControllers are designed to manage the life cycle, layout, and user interactions for a single screen or content area. Drawing graphics directly is usually handled by views or layers, not controllers. While ViewControllers may respond to touch, they do not handle all low-level touch events exclusively. Persistent data storage is handled by other entities like databases or models.

  3. UIKit Navigation Patterns

    When using a navigation controller, which method should you call to transition to a new ViewController?

    1. addSubview()
    2. showSegue()
    3. presentModalViewController()
    4. pushViewController(_:animated:)

    Explanation: pushViewController(_:animated:) is the standard method for adding a ViewController to the navigation stack, resulting in a forward navigation transition. presentModalViewController() is deprecated and not specific to navigation stacks. addSubview() is for views, not controllers. showSegue() is not a UIKit method; segues are used in storyboards, but not with this direct method.

  4. View Life Cycle

    Which method is called after a ViewController's view is loaded into memory but before it appears on the screen?

    1. viewDidAppear
    2. viewDidLoad
    3. viewWillLayoutSubviews
    4. viewWillDisappear

    Explanation: viewDidLoad is called once when the view is loaded, and it is ideal for initial setup. viewDidAppear occurs after the view is already visible. viewWillDisappear is called when the view is about to go away. viewWillLayoutSubviews is about to layout its subviews and can be called multiple times, not specifically after loading.

  5. View Properties

    Which property of UIView determines whether or not a view can be seen by the user?

    1. canFocus
    2. isSelected
    3. isActive
    4. isHidden

    Explanation: isHidden is a Boolean property that controls the visibility of a view. Setting it to true will hide the view from the user. canFocus is not used to control visibility, but is related to focus-based interaction. isSelected is for selectable elements but does not affect basic visibility. isActive is not a standard visibility property in views.

  6. Autoresizing Mask

    What is the effect of setting a view’s autoresizingMask property in UIKit?

    1. It hides the view automatically
    2. It defines how the view resizes when its superview’s bounds change
    3. It disables user interaction on the view
    4. It triggers manual redraws of the view

    Explanation: autoresizingMask specifies how a view’s size and position adjusts when its superview changes size. It does not hide the view or force redraws. Disabling user interaction requires changing the userInteractionEnabled property. Using autoresizingMask allows for responsive layouts without extra code.

  7. ViewController Presentation

    Which method should you use to present one ViewController modally over another in UIKit?

    1. present(_:animated:completion:)
    2. showViewController()
    3. pushViewController(_:animated:)
    4. displayModal()

    Explanation: present(_:animated:completion:) is used to present a ViewController modally, temporarily covering the existing interface. pushViewController(_:animated:) is for navigation stack transitions, not modal. displayModal() and showViewController() are not valid UIKit methods for presenting a controller.

  8. Root View Concept

    In a ViewController, what is the main top-level container for all other views?

    1. superview
    2. window
    3. view
    4. containerView

    Explanation: The view property of a ViewController is the main container that holds all other subviews within that controller. superview refers to the parent of a specific view, not the controller’s main container. window represents the topmost UI element in the hierarchy but is managed separately. containerView is a custom concept and not the default property for all controllers.

  9. Safe Area Usage

    Why should you use the safeAreaLayoutGuide when placing UI elements in a view?

    1. To ensure UI elements are not covered by the system interface
    2. To add shadow effects to elements
    3. It automatically animates view transitions
    4. It increases the brightness of the view

    Explanation: safeAreaLayoutGuide helps developers ensure that content does not overlap system bars or notches, providing a visually consistent layout. It does not animate transitions, alter brightness, or add shadows. Using safe areas is important for proper appearance across different devices.

  10. Navigation Controller Stack

    What happens when you call popViewController(animated:) on a navigation controller?

    1. The top ViewController is removed and the previous one becomes visible
    2. All ViewControllers are removed from the stack
    3. A new ViewController is added to the stack
    4. The entire navigation controller is dismissed

    Explanation: popViewController(animated:) removes the currently visible ViewController from the navigation stack, displaying the one below it. It does not remove all controllers, add new ones, or dismiss the navigation controller itself. This method is used to navigate backwards in stack-based interfaces.