viewDidLoad calling before init? viewDidLoad calling before init? ios ios

viewDidLoad calling before init?


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).


I know this is a bit old post, but I'll post my point of view anywhere because I think it could help somebody.

Well, I've been in this same situation. I thought that viewDidLoad was being called before init method in my view controller class. But what was really happening was not that: the flow starts on init method, but jumps to viewDidLoad when calling [super init*], so my log messages in viewDidLoad method were being displayed first that those in my custom initialization.

I think that's it. I hope this to save some time to someone.

[Sorry for my English]


I don't know what kind of UIViewController caused this for you but I faced a similar case with UITabBarController.I thought it might help another one facing it with UITabBarController.
As far as I know all viewControllers call init before viewDidLoad, except for the UITabBarController and its subclasses.
As Andrew claims here, UITabBarControllers call loadView inside [super init] method, which causes the call to viewDidLoad. So the viewDidLoad method will be called before init has finished its job.
If you have some thing to setup in viewDidLoad you should perhaps do it inside init method after the call to [super init].


matomo