-1

我如何UIActivityIndicatorView在视图加载之前添加一个。我正在从Web 服务器获取数据。

这是我的代码

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

//这是调用不同的Web服务

[objMobilePrefixParser getMobilePrefix];
[objLanguagePreference  languagePreference];
[objCountryPreferences getCountryIdArr];
4

3 回答 3

1

在单独的方法中添加 ActivityIndi​​cator 并使用它调用它

[self performSelector:@selector(addActivityIndicator) withObject:nil afterDelay:0.1];
于 2013-01-31T07:16:54.357 回答
0

你的意思是进度指示器没有动画。如果是,您需要在单独的线程中执行 startAnimating。[微调器 performSelector:@selector(startAnimating)]

于 2013-01-31T07:18:00.340 回答
0

创建微调器:

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

使用 UIWebView 的 Delegate 方法:

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

}
于 2013-01-31T07:39:14.100 回答