Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidLoad calling before init?

Tags:

I face a strange situation. In my controller, viewDidLoad is calling before init. Is there any technical reason behind that?

like image 750
Sandeep Kumar Avatar asked Jul 02 '10 13:07

Sandeep Kumar


People also ask

What is called before viewDidLoad?

Yes, viewDidLoad method is called before viewDidAppear:. viewDidLoad and viewDidLoad: mean actually different things. You specify : if it has an argument, but viewDidLoad does not, just as a convention. Loaded in memory means ready to use/display. Follow this answer to receive notifications.

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.

Does viewWillAppear get called before viewDidLoad?

viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.

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. Once you receive or send message then this block(observer) is called and then adding that text in array self.


1 Answers

The viewDidLoad method is being called when accessing self.view inside the init method (since self.view should not yet be loaded from the nib the process seems to be fasten so it doesn't return nil).

like image 174
alex-i Avatar answered Sep 19 '22 10:09

alex-i