2013-04-03 37 views
1

我有一个需要在Web视图中访问并且url正在成功访问的url。但问题是时间正在花更多的时间在webview中加载url,因此我需要在加载url时显示加载图片。我正在努力,但无法让它显示加载栏,加载图标或任何可能。如何在加载iPhone应用程序中的Web视图内容时显示加载图像

而且我的代码是在这里不用

NSLog(@"Response ==> %@" ,encodedString); 
//'encodedstring' is my url which need to access 

    // code to show a loading image 
      indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
      indicator.frame = CGRectMake(0, 0, 320, 470); 
      [self.view addSubview:indicator]; 
      [indicator release]; 
      [indicator startAnimating]; 

     UIWebView *webView; 
     webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)]; 
     [webView setDelegate:self]; 

     NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 
          stringByReplacingOccurrencesOfString:@"%22" withString:@""]; 

     NSURL *url2; 
     url2 = [[NSURL alloc] initWithString:urlTwo]; 
     NSLog(@"url2:%@", url2); 

     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2]; 

     [webView loadRequest:requestObj]; 
     [[self view] addSubview:webView]; 

    } 
    } 


-(void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
[indicator stopAnimating]; 
[[self view] addSubview:webView]; 
} 

-(void)webViewDidStartLoad:(UIWebView *)webView 
{ 
[indicator startAnimating]; 
} 
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 
[webView stopLoading]; 
} 

任何人可以在这里解决我的问题,让每一天快乐。提前致谢。

回答

3
-(void)webViewDidFinishLoad:(UIWebView *)aWebView 
{ 

    [indicator stopAnimating]; 
} 
-(void)webViewDidStartLoad:(UIWebView *)aWebView 
{ 
    [indicator startAnimating]; 
} 

-(void)webView:(UIWebView *)aWebView didFailLoadWithError:(NSError *)error 
{ 
    [activityView stopAnimating]; 

} 

你试过吗?

相关问题