iOS Development UIKit Framework 1 — Questions and Answers
Question 1: Which UIKit class is the base class for all visible UI elements?
- UIView (Correct answer)
- UIControl
- UIResponder
- UIWindow
Correct answer: UIView
`UIView` is the fundamental building block for all UIKit UI elements, providing drawing, layout, and event handling.
Question 2: What is the role of UIViewController in a UIKit app?
- Manages a view hierarchy and coordinates with the app's data model (Correct answer)
- Renders graphics directly to the screen
- Handles network requests
- Stores persistent user preferences
Correct answer: Manages a view hierarchy and coordinates with the app's data model
UIViewController manages a single root view and its subviews, acting as the intermediary between the app's data and its views.
Question 3: Which UIViewController lifecycle method is called after the view is loaded into memory?
- viewDidLoad (Correct answer)
- viewWillAppear
- viewDidAppear
- loadView
Correct answer: viewDidLoad
`viewDidLoad` is called once after the view controller's view is loaded into memory, making it ideal for one-time setup.
Question 4: What does Auto Layout do in UIKit?
- Defines the size and position of views using constraint relationships (Correct answer)
- Automatically generates view code from storyboards
- Resizes images to fit their containers
- Manages view controller transitions
Correct answer: Defines the size and position of views using constraint relationships
Auto Layout uses constraints to dynamically calculate the size and position of every view in the hierarchy.
Question 5: Which UIKit class is used to display a scrollable list of items?
- UITableView (Correct answer)
- UICollectionView
- UIScrollView
- UIStackView
Correct answer: UITableView
UITableView displays data in a single-column scrollable list with rows organized into optional sections.
Question 6: What is the purpose of a UITableViewCell reuse identifier?
- To efficiently recycle cells as they scroll off screen (Correct answer)
- To uniquely identify each row's data
- To style cells with a specific color
- To register the cell class with Interface Builder
Correct answer: To efficiently recycle cells as they scroll off screen
Reuse identifiers allow UITableView to dequeue previously allocated cells instead of creating new ones, improving scroll performance.
Which UIKit class is the base class for all visible UI elements?