how to show a loading bar or progress bar in iPhone application whiele fetching data
I have an iPad application when view is loaded, i am calling method after some time duration so i want to display a loading bar till method is called and data is loaded.
I am Using NSTimer
to call a method in viewDidLoad
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(loadNews) userInfo:nil repeat开发者_如何学JAVAs:NO];
Use Activity Indicator to show progress bar or loading view.... like below.... in viewdidload..
CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
self.activityIndicator = [[UIActivityIndicatorView alloc]
initWithFrame:frame];
[self.activityIndicator sizeToFit];
self.activityIndicator.autoresizingMask =
(UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[activityIndicator startAnimating];
UIBarButtonItem *loadingView = [[UIBarButtonItem alloc]
initWithCustomView:self.activityIndicator];
loadingView.target = self;
self.navigationItem.rightBarButtonItem = loadingView;
You can use a UIProgressView to display loading progress. The Mail app uses this when downloading messages. For indefinite time periods, use a UIActivityIndicatorView instead.
It's discussed in the iOS HIG.
Rather Do
[NSThread detachNewThreadSelector:@selector(loadNews) toTarget:self withObject:nil];
Then stop the loadingview when you are finished using something like
[activityIndicator setHidden:YES];
Hope this helps you.
I like to use MBProgressHUD. It lets you easily customize your loading progression, with different states. Like initialization, downloading, cleaning...
精彩评论