I would like to display a hud while the content is loading (and show the progress), but unfortunately it doesn't work properly. The hud appears on the screen when statusUpdate is 0.100000, but the loading bar doesn't moves until statusUpdate is not 1.000000 and the page loading finished. (After the view loaded sucessfully it animates from 0-100%.) I would appreciate if somebody could show me what I'm doing wrong.
// ViewDidLoad
[self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
HUD.delegate = self;
HUD.labelText = @"Uploading";
[HUD show:YES];
[self hud:self.webView.estimatedProgress];
if ([keyPath isEqualToString:@"estimatedProgress"] && object == self.webView) {
// [self.progressView setAlpha:1.0f];
// [self.progressView setProgress:self.webView.estimatedProgress animated:YES];
NSLog(@"%f", self.webView.estimatedProgress);
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
NSLog(@"%f", self.webView.estimatedProgress);
}
}
- (void) hud: (double)statusUpdate {
NSLog(@"STATUS %f", statusUpdate);
int myInt = (int)statusUpdate;
HUD.progress = (float)myInt;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire