MBProgressHUD指示器不隐藏

Moh*_*hid 2 ios mbprogresshud

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

我使用下面的代码::

在.h文件中

MBProgressHUD *HUD;
Run Code Online (Sandbox Code Playgroud)

在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";

}
Run Code Online (Sandbox Code Playgroud)

并在webViewDidFinishLoad中

- (void)webViewDidFinishLoad:(UIWebView *)web
{
    [HUD hide:TRUE]; //it does not work for me :(
}
Run Code Online (Sandbox Code Playgroud)

Moh*_*hid 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];
}
Run Code Online (Sandbox Code Playgroud)