2012-03-15 38 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