2013-04-03 65 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]; 

} 

你試過嗎?

相關問題