tags:

views:

279

answers:

1

Ok, it's pretty straight forward to display the Activity Indicator and it fades away when the web page is loaded, but what happens if I want my App to CANCEL loading the web page after XXX seconds?

Like, hey this page is tooooooo slow loading, even thought I have a connection, I still want to cancel (App talking here). HUD is a home brewed Activity Indicator that I think I can hack that but wondering if anyone has a tip. NSTimer? thanks!

- (void)viewDidLoad {

CGRect webRect = CGRectMake(0.0f, 0.0f, 300.0f, 300.0f);
webView = [[UIWebView alloc] initWithFrame:webRect]; 
webView.scalesPageToFit=YES;

[[self webView] setDelegate:self];

NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:webView];

}

// start activity indicator
- (void)webViewDidStartLoad:(UIWebView *)webView {     
UIWindow *window = [UIApplication sharedApplication].keyWindow;

HUD = [[MBProgressHUD alloc] initWithWindow:window];
[window addSubview:HUD];

HUD.delegate = self;
HUD.labelText = @"Loading . . .";
[HUD show:YES];

}

//stop activity indicator
- (void)webViewDidFinishLoad:(UIWebView *)webView {   
[HUD hide:YES];

}

A: 

Hi There,

It was very helpful for me the code [[self webView] setDelegate:self]; is very much important. but many failed to say this.. thanks a lot.

santhosh kumar