2

MBProgressHUD 有点问题。我有一个 web 视图,想在数据加载时显示 HUD。HUD 出现但仅停留几秒钟并已消失,但 web 视图未完成加载。

-(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);}
4

2 回答 2

5

删除 showWhileExecuting 方法并在 UIWebView 下面的委托方法中隐藏 hud 然后它会正常工作

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [HUD hide:YES];
}
于 2012-03-15T11:12:29.670 回答
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;
   }
}
于 2012-03-15T11:11:20.373 回答