开发者

iPhone UIActivityIndicatorView While Loading UIViewController

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 h开发者_如何学运维ave 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜