In my iOS app, I have a UITabBarController, and its viewControllers list looks like [vc1, vc2], which are of class MyVC1 and MyVC2 respectively, both of which subclass UIViewController. MyVC1 overrides viewWillAppear, and the overwritten version prints something so I know when it is called. (This is to isolate a larger problem I had, which was a view not appearing.)
My issue is that when the app first starts up and vc1 is the selected tab, nothing is printed, meaning its viewWillAppear is not being called. If I switch tabs and then go back to vc1, something does get printed, so vc1's viewWillAppear is not being called until I switch back to it from another tab.
Is there any way to have vc1 call viewWillAppear as soon as the app starts up, without needing to switch tabs? Honestly, I'm surprised this wasn't the default behavior already.
I just made a new test app in Xcode with nothing but a UITabViewController (and its two child view controllers) in Main.storyboard, and when I override viewWillAppear for the first child, my "view will appear" log prints every time (including on app launch).
Here are a couple things that could cause viewWillAppear to not be called:
You also might try seeing if viewWillAppear is getting called for your UITabBarController, and if not, is it being called for its parent or presenting view controller? And so on until you find where the holdup is.
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