Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidLoad(), LoadView() [duplicate]

What is the difference between viewDidLoad() and LoadView()? In what way are they different from each other?

Which one is better when we develop applications without using XIB ?

Thanks .

like image 311
iOS Avatar asked Mar 02 '11 05:03

iOS


People also ask

What is the difference between loadView and viewDidLoad?

loadView is the method that actually sets up your view (sets up all the outlets, including self. view). viewDidLoad you can figure out by its name. It's a delegate method called after the view has been loaded (all the outlets have been set) that just notifies the controller that it can now start using the outlets.

How many times does viewDidLoad get called?

viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.

Is viewDidLoad only called once?

viewDidLoad method is called only once in ViewController lifecycle. The reason retrieveMessage() is called in viewDidLoad because it's adding observer to start listening for received and sent message.

What is viewDidLoad?

viewDidLoad is called when the ViewController has loaded its view hierarchy into memory. This is the point where you can perform your customized initialisation for your view controller. For instance, if your view controller has a UILabel and you want to set a custom text to it, this is the point where you do that.


1 Answers

ViewDidLoad is called when your view loading is finished and loadView is called when loading starts.

And when you make a new project you see comments on these methods which clearly gives a tip when you should use which function

see this

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

These comments are clear and easy to understand.

like image 102
Ishu Avatar answered Oct 22 '22 02:10

Ishu