-1

How I add an UIActivityIndicatorView before the viewload. I am fetching data from a web server.

Here is my code

spinner=[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(225, 115, 30, 30)];
[spinner setBackgroundColor:[UIColor clearColor]];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:spinner];
[spinner startAnimating];


objCountryPreferences=[[CountryPreferences alloc]init];
objLanguagePreference=[[LanguagePreference alloc]init];
objMobilePrefixParser=[[MobilePrefixParser alloc]init];

//this is calling different web services

[objMobilePrefixParser getMobilePrefix];
[objLanguagePreference  languagePreference];
[objCountryPreferences getCountryIdArr];
Nimantha
  • 6,405
  • 6
  • 28
  • 69

3 Answers3

1

Add ActivityIndicator in separate method and call it using

[self performSelector:@selector(addActivityIndicator) withObject:nil afterDelay:0.1];
Madhu
  • 1,542
  • 1
  • 14
  • 30
0

Do you mean the progress indicator is not animating. If YES, you need to perform startAnimating in separate thread. [spinner performSelector:@selector(startAnimating)]

Srinidhi
  • 719
  • 5
  • 8
0

Create spinner :

  self.spinner=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.spinner.frame=CGRectMake(152,183,60,60);
    // display spinner in StatusBar it Optional for you
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [self.spinner sizeToFit ];    
      /*-----------Change Size of UIActivityIndicatorView-------------*/
        self.spinner.transform = CGAffineTransformMakeScale(2, 2);
    [self.webView addSubview:self.spinner];
   

Use Delegate method of UIWebView:

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.spinner startAnimating];
     // display  spinner in StatusBar it Optional for you
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.spinner stopAnimating];
    // Remove  spinner in StatusBar it Optional for you
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

}
Nimantha
  • 6,405
  • 6
  • 28
  • 69
iPatel
  • 46,010
  • 16
  • 115
  • 137