Girish
Girish

Reputation: 4712

UIWebView does not load the URL

I have very small problem while loading the URL in UIWebView. I have one UIButton, on clicking of it, I add the UIView which contains UIWebView, UIButton & Title bar. Code used is as follows -

    [self.view addSubview:vwOnline];
    vwOnline.bounds = self.view.bounds;

    //Load webview
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", objWine.strOnlineURL]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [wbvwOnline loadRequest:request];

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    //Show activity indicator
    [indicator startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //Remove Activity indicator
    [indicator stopAnimating];
    [indicator removeFromSuperview];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"Error - %@", error);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Find A Vino" message:@"Error while loading request." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    alert.tag = 1;

    //Remove Activity indicator
    [indicator stopAnimating];
    [indicator removeFromSuperview];
}

By doing above code, most of times the UIWebView does not loads the URL which I passed in the object objWine.strOnlineURL. If I clicked the back button & again clicked on the button to load the URL, it goes into the - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error delegate method of UIWebView. If anyone knows the solution, then please help me.

Upvotes: 1

Views: 3915

Answers (3)

Rahul Gupta
Rahul Gupta

Reputation: 808

when you are going back, make request to nil and load empty htmlstring to webview. One more thing, remove [indicator removeFromSuperview]; line from

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
-(void)webViewDidFinishLoad:(UIWebView *)webView

Upvotes: 1

arthankamal
arthankamal

Reputation: 6413

Instead of adding your webview on your button click each time. Why don't you add your webview into your viewDidLoad and hide and show it in your button click.

Upvotes: 1

iPatel
iPatel

Reputation: 47049

use

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];

if it is work fine then check objWine.strOnlineURL

otherwise it is clear :)

Upvotes: 0

Related Questions