Two objective-c methods, -(void) viewDidLoad and -(void)loadView are methods called upon execution of a program but whats the different between them?
-
1The UIViewController Class Reference explains this very clear. – SVGreg Mar 05 '12 at 21:24
3 Answers
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
.

- 12,391
- 3
- 57
- 92
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];
...
}

- 2,320
- 1
- 13
- 17
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?

- 1
- 1

- 5,525
- 8
- 33
- 69