I have a webview. The activity indicator animates beside the date in the status bar when I have internet access. When I don't have internet access, an alert comes up, I click dismiss but the activity indicator keeps on going. How do I make it go away? Here is my .h and .m file. Thank you kindly.
Code:
#import <UIKit/UIKit.h>
@interface WebsiteButton : UIViewController {
IBOutlet UIWebView *myWebView;
}
@property (nonatomic, retain) UIWebView *myWebView;
@end
.m
#import "WebsiteButton.h"
@implementation WebsiteButton
@synthesize myWebView;
-(void)viewDidLoad {
[super viewDidLoad];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://website.com"]]];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
}
- (void)webViewDidStartLoad: (UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad: (UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)webView: (UIWebView *)webView didFailLoadWithError: (NSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"You need an internet connection to access this page" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
-(void)dealloc
{
[myWebView release];
[super dealloc];
}
@end
I thought the code looked good. I've tried it on my device and the activity indicator does not keep on going when there is no internet connection (airplane mode though). Does that mean I should ignore the iPhone simulator perpetual animation and go by what the device shows?