kumar Sudheer
kumar Sudheer

Reputation: 705

How to show loading image while loading the content of the web view in iPhone application

I have an url which need to access in web view and the url is accessing successfully. but the issue is time is taking more to load the url in webview and hence I need to show a loading image while loading an url. I am trying for that, but not able to get it to show loading bar, loading icon or whatever it may be.

And my code is here goes

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

Can anybody is here to solve my issue and make the day happy. Thanks in advance.

Upvotes: 1

Views: 712

Answers (1)

Arun
Arun

Reputation: 3404

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

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

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

}

have u tried that?

Upvotes: 2

Related Questions