
Question:
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 repeats:NO];
Answer1: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;
Answer2:You can use a <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIProgressView_Class/Reference/Reference.html" rel="nofollow">UIProgressView</a> to display loading progress. The Mail app uses this when downloading messages. For indefinite time periods, use a <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIActivityIndicatorView_Class/Reference/UIActivityIndicatorView.html" rel="nofollow">UIActivityIndicatorView</a> instead.
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/5TUsW.jpg" data-original="https://i.stack.imgur.com/5TUsW.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
It's discussed in the <a href="https://developer.apple.com/library/safari/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html" rel="nofollow">iOS HIG.</a>
Answer3: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.
Answer4:I like to use <a href="https://github.com/jdg/MBProgressHUD" rel="nofollow">MBProgressHUD</a>. It lets you easily customize your loading progression, with different states. Like initialization, downloading, cleaning...