MBProgressHud不适用于导航栏

时间:2013-04-17 17:03:58

标签: objective-c mbprogresshud

我在导航项中有一个buttono,其动作是BUTTON_ACTION。通过按下它,MBProgressHUD被激活并且动作有效。但是“dimBackground”使scrren“隐藏”,在导航栏上不起作用,并且可以在MBProgressHUD期间再次按下该按钮。 代码是:

  HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];

    // Regiser for HUD callbacks so we can remove it from the window at the right time
    HUD.delegate = self;
    HUD.labelText=@"Buscando Bares...";
    HUD.dimBackground = YES;

    // Show the HUD while the provided method executes in a new thread
    [HUD showWhileExecuting:@selector(BUTTON_ACTION) onTarget:self withObject:nil animated:YES];

我试着用:

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        [self.navigationController.view addSubview:HUD];

有什么想法吗?提前谢谢。

2 个答案:

答案 0 :(得分:16)

要使MBProgressHUD显示在包括UINavigationBar在内的所有UI控件上方,您必须执行以下操作:

 HUD = [[MBProgressHUD alloc] initWithWindow:self.view.window];
 [self.view.window addSubview:HUD];

答案 1 :(得分:1)

@ararog是对的,但做起来也很简单

    _progressHUD = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];