2012-03-15 68 views
2

MBProgressHUD出现问题。我有一个webview,并希望在数据加载时显示HUD。 HUD显示,但只停留几秒钟,并已消失,但webview没有完成加载。MBProgressHUD UIWebView

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

回答

5

除去showWhileExecuting方法和隐藏HUD中的UIWebView的下面委托方法然后它会正常工作

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    [HUD hide:YES]; 
} 
+0

对不起。没有得到它。如果我删除showWhileExecuting它根本不出现。你能否详细解释一下。 – halloway4b 2012-03-15 11:22:53

+0

这一行不需要[HUD showWhileExecuting:@selector(loadingWebView)onTarget:self withObject:nil animated:YES]; – Narayana 2012-03-15 11:27:14

+0

如果我删除此行,则HUD根本不会显示。 – halloway4b 2012-03-15 11:30:28

1

我们从来没有集成Web视图与MBProgressView HUD,而不是使用这个你应该使用UIActivityIndi​​cator在这里,并在此委托web视图的停止& resignFromSuperView:

  • (无效)webViewDidFinishLoad: (UIWebView *)webView

你可以手动隐藏HUD在这个代表:

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    [HUD hide:YES]; 
    if(HUD!=nil) 
    { 
     [HUD removeFromSuperview]; 
     [HUD release]; 
     HUD=nil; 
    } 
} 
+0

'[HUD retainCount]> 0' 是完整无义。 – bbum 2012-03-15 15:08:40

+2

@bbum:就这样。我承认这件事,那是错误的,但现在我更新了这个, – kulss 2012-03-16 07:35:35