1

Two objective-c methods, -(void) viewDidLoad and -(void)loadView are methods called upon execution of a program but whats the different between them?

SilentK
  • 587
  • 7
  • 20
Airon Zagarella
  • 707
  • 2
  • 11
  • 17

3 Answers3

6

Do you mean viewDidLoad and loadView? viewDidLoad is a method called when your view has been fully loaded. That means all your IBOutlets are connected and you can make changes to labels, text fields, etc.

loadView is a method called if you're (typically) not loading from a nib. You can use this method to set up your view controller's view completely in code and avoid interface builder altogether.

You'll typically want to avoid loadView and stick to viewDidLoad.

Ash Furrow
  • 12,391
  • 3
  • 57
  • 92
1

Use -(void)loadView when you create the view. Typically usage is:

-(void)loadView {
    UIView *justCreatedView = <Create view>;
    self.view = justCreatedView;
}

Use -(void)viewDidLoad when you customize the appearance of view. Exapmle:

-(void)viewDidLoad {
    self.view.backgroundColor = [UIColor blackColor];
    ...
}
SVGreg
  • 2,320
  • 1
  • 13
  • 17
0

i think you are talking about loadView and viewDidLoad.

loadView is a method that you not using a nib file - you use it to programmatically 'write' your interface

viewDidLoad fires automatically when the view is fully loaded. you can then start interacting with it.

more to read read in the discussion here iPhone SDK: what is the difference between loadView and viewDidLoad?

Community
  • 1
  • 1
Sebastian Flückiger
  • 5,525
  • 8
  • 33
  • 69