Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Thomas Nilsen
14,957 PointsDifference between LoadView and ViewDidLoad
I have been googling around trying to find a satisfying answer, but most of the posts is quite old, so I'd love an explanation.
Say I created a button, I usually do this in viewDidLoad. But if I wanted to customize it, would the be in LoadView, or am I way of? I'm asking in terms of no storyboard usage :)
1 Answer
John W
21,558 PointsloadView is called by the view controller to load the view. It is the active action of creating and instantiating the UIView object. This is where the view controller decides how the view should look based on what it knows from the storyboard.
viewDidLoad is called after loadView has completed all its tasks and the UIView is ready for display. It is where you initialize any properties of the view or the view controller object and finalize them before viewWillAppear is called.
If you are using storyboard, you would almost never use loadView. Even if you do, most of the initialization of different properties of the view should be done in viewDidLoad, as stated in the Apple documentation. This method is very rarely overridden unless you are creating a view controller entirely programmatically without storyboard.