views:

73

answers:

2

Hi there, I've an application with a UITabBarController with five tabs. Tests on real device show that switching from a tab to another, may take one or more seconds to load the views, because I also have to download some data from the Internet.

What I would like to do is to show a UIActivityIndicatorView while the view is loading, but I couldn't find a solution. Maybe I haven't searched the right way.

Could someone help me?

+1  A: 

You should download any data with an asynchronous request, ASIHTTPRequest is a nice wrapper for this.

Then for the UIActivityIndicatorView these are popular options:

  1. Show it on the tab, BEFORE actually loading anything else in the view. And when the data is ready just hide it and show the complete info.
  2. Show your incomplete view, and add an overlay with the UIActivityIndicatorView.
pablasso
+1  A: 

The way I do it :

Create a LoadingViewController Class with a UILabel, a UIActivityIndicator and black background .

In the ViewDidLoad method, i set :

[self.view setAlpha:0.0];
[self.activityIndicator startAnimating];

I implement two methods :

-(void)appear{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self.view setAlpha:0.65];
[UIView commitAnimations];
}

-(void)disappear{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self.view setAlpha:0.0];
[UIView commitAnimations];
}

In the label you can set a custom text.

Import this class in the class you are working on and just call :

[loadingViewController appear];

and

[loadingViewController disappear];

I don't have a Mac with me right now and can't verify if i just wrote any mistakes but I hope you get the idea :)

I always prefer to make a custom class for this in case I'll need it at many places in my app.

Christophe Konig