Reputation: 4625
I have an app that has four tabs. I have four UINavigationControllers, each of which is bound to the UITabBarController by setting the TabBarItem property of each controller and then adding the controllers to the UITabBarController. That's all standard iOS fare.
One of these tabs loads up a UITableView that displays some data from a remote web service. Because the web service calls routinely take about 1.5 seconds to complete and deserialize, I'd like to display a "loading" UIView with the text "Loading..." when the corresponding tab is selected. I've tried this a couple of ways:
assigning a delegate to the ViewControllerSelected event on the UITabBarController, and checking to make sure that the controller selected is the one I'm interested in. Then I try to show the "loading" UIView. This all happens in AppDelegate;
overriding the ViewWillAppear and ViewWillDidAppear methods on the controller itself. Show the LoadingHUDView in the ViewWillAppear method and hide in the ViewDidAppear method.
In both cases:
(And yes, I am aware that I don't need to use lhv.SharedApplication.KeyWindow in AppDelegate because I have the local "window" member available to me.)
The problem is that the "loading" UIView doesn't render until AFTER the UINavigationController has rendered its view. I want the LoadingHUDView to appear IMMEDIATELY, as soon as the UITabBarController is tapped. I've tried using InvokeOnMainThread() as well, but no luck there.
Any ideas?
Upvotes: 1
Views: 315
Reputation: 4625
>.< Figured it out. Just had to spin up the loading UIView in a new thread at the beginning of ViewWillAppear or ViewDidAppear. Then just have to do the cleanup at the end of the respective method by removing the view from the superview. Should've thought of that one a long time ago! D'oh!
Upvotes: 2