MBProgressHUD指示器不隐藏

时间:2011-12-26 17:38:04

标签: ios mbprogresshud

我能够在viewDidLoad中成功显示HUD指示符,但在webview完全加载时无法在webViewDidFinishLoad方法中隐藏它。请帮忙。

我正在使用以下代码::

<。>文件中的

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 :(
}

4 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分:3)

试试这个

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

答案 2 :(得分:2)

您不应该从MBProgressHUD致电viewDidLoad,尝试从viewDidAppear拨打电话,一切都应该正常。

答案 3 :(得分:0)

尝试使用此类方法删除它:

+ (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";
}
相关问题