how to show a loading bar or progress bar in iPhone application whiele fetching data

徘徊边缘 提交于 2019-12-08 05:02:53

问题


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];

回答1:


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;



回答2:


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.




回答3:


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.




回答4:


I like to use MBProgressHUD. It lets you easily customize your loading progression, with different states. Like initialization, downloading, cleaning...



来源:https://stackoverflow.com/questions/6881641/how-to-show-a-loading-bar-or-progress-bar-in-iphone-application-whiele-fetching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!