I face a strange situation. In my controller, viewDidLoad
is calling before init
. Is there any technical reason behind that?
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.
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With