Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does UIViewController class do in viewDidLoad? [duplicate]

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.

like image 452
johnyu Avatar asked Mar 29 '13 14:03

johnyu


1 Answers

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.

like image 185
Seamus Campbell Avatar answered Sep 29 '22 10:09

Seamus Campbell