I've gotten diagnostics from a couple of my users experiencing a rare issue. The logs in the diagnostics clearly show that the view controller where the issue occurs gets viewDidLoad called twice, and then does not get viewWillAppear or viewDidAppear. This triggers a bug for me because the view controller loads the data it's meant to display in viewWillAppear.
I can work around this by changing my data loading logic, but I'd like to know what the underlying issue is. Can anyone point me to some possible ways I could be triggering this weird UIKit behavior?
viewDidLoad() is called as a consequence of accessing the view controller's view when it is nil - the most obvious way to cause something like this to happen would be to reset the view controller's view to nil. However, this code path is not thread safe, so if you are accessing view from multiple threads this could happen.
In general not getting viewWillAppear() or viewDidAppear() callbacks is a consequence of view controller life cycle issues. If your using view controller containment for example, adding the view of a view controller to its parent after the parent has already received viewDidAppear() will require you to manage the appearance cycle yourself by calling UIViewController.beginAppearanceTransition(:animated:) and UIViewController.endAppearanceTransition() yourself.
That said, if any of this doesn't seem to match what your doing, it would be great to get a bug report with a sample project to see if there is an issue in the OS – if you end up needing to file a feedback report, please post the feedback number here so we can track the issue!