5

As in the title, I was wondering what is the "default" implementation of viewDidLoad in UIViewController? Does it really do anything? Also does it matter if in my UIViewController's subclass I write

-(void)viewDidLoad{
  [super viewDidLoad];
  /*custom code here*/
}

or

-(void)viewDidLoad{
  /*custom code here*/
  [super viewDidLoad];
}

?

P.S. This is not a duplicate, in other questions people ask when should they call [super viewDidLoad], while my main concern is what the UIViewController's implementation do with it.

Ravi Gautam
  • 960
  • 2
  • 9
  • 20
johnyu
  • 2,152
  • 1
  • 15
  • 33

2 Answers2

5

That implementation does nothing, and can safely be removed if you have no setup to do after the view loads. However, it is fairly rare to have no custom setup to do here; this is the place where your view controller is telling you that all of its UI objects are available to customize with data. It's included in the template with an empty implementation as a reminder: here's where to do this.

As far as when to call super: the general expectation is that setup or initialization methods call super before doing work, and teardown methods call super after doing work.

Seamus Campbell
  • 17,816
  • 3
  • 52
  • 60
0

ViewDidLoad Method Called after the controller’s view is loaded into memory. This is where you want to instantiate any instance variables and build any views that live for the entire lifecycle of this view controller. However, the view is usually not yet visible at this point

This method is called regardless of whether the view hierarchy was loaded from a nib file or created programmatically in the loadView method. You usually override this method to perform additional initialization on views that were loaded from nib files.

For detail Information

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56