Junior — Middle
At what stage of the lifecycle does the creation and configuration of a view in UIViewController occur?
sobes.tech AI
Answer from AI
Creating and configuring a view in UIViewController occurs in the lifecycle methods loadView() and viewDidLoad().
- In
loadView(), the root view of the controller is usually created and initialized if a storyboard or xib is not used. - In
viewDidLoad(), additional setup of the view takes place after it has been loaded, such as adding subviews, setting properties, and configuring data.
Example:
override func loadView() {
self.view = UIView()
self.view.backgroundColor = .white
}
override func viewDidLoad() {
super.viewDidLoad()
// Setup subviews
}