-4

I am new to both iOS development and programming in general. I need some clarification as to what sort of things should be declared in the viewDidLoad function of a UIViewController subclass

Thanks

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • 1
    Please check [Apple Documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/viewDidLoad) for more information. – Omar Lahlou Aug 06 '15 at 22:36
  • Or the [Resource Management in View Controllers](https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10-SW36). – Rob Aug 06 '15 at 22:54

3 Answers3

1

In order to properly understand what viewDidLoad does, you should understand the View Controller Lifecycle. The best point to start is reading the Apple Documentation, e.g. the learning guides for developing iOS Apps: https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson4.html

dirkgroten
  • 20,112
  • 2
  • 29
  • 42
0

Everything you write inside the viewDidLoad function will run the the View(which can be TableView, ViewController & more..) is loaded.

For example, if you got a label called 'label' and you want to set it's by the code so you type:

override func viewDidLoad() {
    super.viewDidLoad()
    label.text = String("any text here")
}

and then the text of the label will change when the View will load.

vacawama
  • 150,663
  • 30
  • 266
  • 294
Eliko
  • 1,137
  • 4
  • 16
  • 26
0

Declare elements that don't need to be refreshed or recreated when the view reloads. For instance, viewDidLoad is called only when it is created while viewDidAppear will be called every time the view is shown.

Read up on some apple docs.

lukeswitz
  • 553
  • 4
  • 14