2

got a little problem with MBProgressHUD. I have a webview and want to display the HUD while the data is loading. The HUD appears but stays only for a few seconds and disappears already but the webview didn't finish with loading.

-(void)viewDidAppear:(BOOL)animated{

// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];

// Add HUD to screen
[self.view.window addSubview:HUD];

// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;

HUD.labelText = @"Loading";
HUD.detailsLabelText = @"updating data";

// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(loadingWebView) onTarget:self withObject:nil animated:YES];}

- (void) loadingWebView {

NSString *fullURL = beverageViewString; 
NSURL *url = [NSURL URLWithString:fullURL]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[beverageView loadRequest:requestObj];
NSLog(@"%@",beverageViewString);}
halloway4b
  • 573
  • 1
  • 11
  • 23

2 Answers2

5

remove the showWhileExecuting method and hide hud in the below delegate method of UIWebView then it will work fine

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [HUD hide:YES];
}
James Zaghini
  • 3,895
  • 4
  • 45
  • 61
Narayana Rao Routhu
  • 6,303
  • 27
  • 42
1

We never integrated web view with MBProgressView HUD , instead of using this you should to use UIActivityIndicator over here and stop & resignFromSuperView at this delegate of webView:

  • (void)webViewDidFinishLoad:(UIWebView *)webView

u can manually hide HUD at this delegate :

 - (void)webViewDidFinishLoad:(UIWebView *)webView
{
   [HUD hide:YES];
   if(HUD!=nil)
   { 
       [HUD removeFromSuperview];
       [HUD release];
       HUD=nil;
   }
}
kulss
  • 2,057
  • 1
  • 14
  • 16