NovaJoe
NovaJoe

Reputation: 4625

Any ideas on firing off a "loading" UIView when a particular item in a UITabBarController is selected?

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:

In both cases:

  1. The "loading" UIView is a local variable (lhv) and is already setup with the text I want.
  2. lhv.SharedApplication.KeyWindow.Add(lhv);
  3. lhv.StartAnimating(); (the UIView contains a UIActivityIndicatorView)
  4. Perform the service calls and refresh the UITableView
  5. lhv.StopAnimating();
  6. lhv.RemoveFromSuperview();

(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

Answers (2)

Rams Chinni
Rams Chinni

Reputation: 31

declare spinner separatly; and add MyView.addsubview(_spinner);

Upvotes: 0

NovaJoe
NovaJoe

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

Related Questions