1

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

我的代码在这里

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

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

4

1 回答 1

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

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

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

}

你试过吗?

于 2013-04-03T13:37:47.197 回答