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.
use
if it is work fine then check
objWine.strOnlineURL
otherwise it is clear :)
Instead of adding your
webview
on yourbutton
click each time. Why don't you add yourwebview
into yourviewDidLoad
andhide
andshow
it in yourbutton
click.when you are going back, make request to nil and load empty
htmlstring
towebview
. One more thing, remove[indicator removeFromSuperview];
line from