Hello, I'm trying to display a UIAlertView when there is a connection error/no internet connection in my UIWebView. I turned off my wifi so the simulator would get no internet, and the alert displayed nicely, however when you click refresh in the webview it doesn't pop up again.
Here is a video of the issue:
And here is my total UIwebview code:
My issue seems to be related perhaps that the didfailloadwitherror isn't recognized when I'm refreshing the initial loaded web page.
Thanks for any help offered!
Here is a video of the issue:
YouTube: Screen recording
And here is my total UIwebview code:
Code:
#import "AlaskaFish.h"
@implementation AlaskaFish
@synthesize webView;
@synthesize activityIndicator;
@synthesize refreshButton;
@synthesize backButton;
@synthesize forwardButton;
@synthesize backButtonT;
@synthesize forwardButtonT;
@synthesize stopButton;
@synthesize toolbarStop;
@synthesize toolbarRefresh;
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown);
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Alaska";
[webView addSubview: activityIndicator];
NSString *urlAddress = @"http://www.adfg.alaska.gov/index.cfm?adfg=fishregulations.sport";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
-(void)actualizeButtons {
backButton.enabled = [webView canGoBack];
forwardButton.enabled = [webView canGoForward];
backButtonT.enabled = [webView canGoBack];
forwardButtonT.enabled = [webView canGoForward];
}
-(IBAction)refreshWebView {
toolbarStop.hidden = NO;
toolbarRefresh.hidden = YES;
[webView reload];
}
-(IBAction)stop {
toolbarStop.hidden = YES;
toolbarRefresh.hidden = NO;
[webView stopLoading];
}
-(IBAction)goBack {
[webView goBack];
[self actualizeButtons];
}
-(IBAction)goForward {
[webView goForward];
[self actualizeButtons];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { NSLog(@"Did fail load with error: %@", [error description]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"Check your Internet connection before refreshing."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
[activityIndicator stopAnimating];
toolbarStop.hidden = YES;
toolbarRefresh.hidden = NO;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicator stopAnimating];
toolbarStop.hidden = YES;
toolbarRefresh.hidden = NO;
[self actualizeButtons];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[activityIndicator startAnimating];
toolbarStop.hidden = NO;
toolbarRefresh.hidden = YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
[refreshButton release];
[backButton release];
[forwardButton release];
[backButtonT release];
[forwardButtonT release];
[stopButton release];
[activityIndicator release];
[toolbarStop release];
[toolbarRefresh release];
[webView release];
}
@end
My issue seems to be related perhaps that the didfailloadwitherror isn't recognized when I'm refreshing the initial loaded web page.
Thanks for any help offered!