2011-12-26 79 views
2

我能夠在viewDidLoad中成功顯示HUD指示符,但在webview完全加載時無法將其隱藏在webViewDidFinishLoad方法中。請幫忙。MBProgressHUD指示器不會隱藏

我使用下面的代碼::

在.h文件中

MBProgressHUD *HUD; 

在viewDidLoad中

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSString *query = [[NSString alloc] initWithFormat:@"http://localhost/index.php?uid=%@", [[UIDevice currentDevice] uniqueIdentifier]]; 
    NSURL *url = [[NSURL alloc] initWithString:query]; 

    NSString *response = [[NSString alloc] initWithContentsOfURL:url]; 
    if(response) 
    { 
      [webView loadRequest:[NSURLRequest requestWithURL:url]]; 
    } 
    else 
    { 
     //NSLog(@"err %@",response); 
    } 


    HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain]; 
    HUD.delegate = self; 
    HUD.labelText = @"loading"; 

} 

和webViewDidFinishLoad

- (void)webViewDidFinishLoad:(UIWebView *)web 
{ 
    [HUD hide:TRUE]; //it does not work for me :(
} 
+0

如果找不到修復程序,請給[SVProgressHUD](https://github.com/samvermette/SVProgressHUD)一個試試。在你的情況,這將是簡單的調用'[SVProgressHUD showWithStatus:@「加載」]'然後'[SVProgressHUD解僱]' – samvermette

+0

謝謝,SVProgressHUD正是我想要的,但它奇怪的是,它只適用於Xcode模擬器和不在我的iPad上,我做錯了什麼? –

+0

嘗試在'viewDidAppear:'而不是'viewDidLoad'中顯示它。 – samvermette

回答

10

我有固定的錯誤,我從移動代碼viewDidLoad中webViewDidStartLoad一切這次工作很好:)

- (void)webViewDidStartLoad:(UIWebView *)web 
{ 
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    HUD.labelText = @"loading"; 
} 

- (void)webViewDidFinishLoad:(UIWebView *)web 
{ 

    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
} 
0

試試用這個刪除類方法d:

+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated 

- (void)webViewDidFinishLoad:(UIWebView *)web 
{ 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
} 

如果您使用此方法,那麼你應該考慮重寫你的viewDidLoad中這樣說:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    //... 

    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
    HUD.labelText = @"loading"; 
} 
3

試一下這個

[HUD hide:YES]; 
if(HUD!=nil && [HUD retainCount]>0) 
{ 
    [HUD removeFromSuperview]; 
    [HUD release]; 
    HUD=nil; 
} 
2

你不應該從viewDidLoadMBProgressHUD,嘗試從viewDidAppear調用它,一切都應該很好地工作。