2

In my application I have UINavigationController inside UITabBar When I display my HUD the whole screen is locked except TabBar. So the only way to dismiss my HUD is to tap on a tab. I would also like to dismiss it when I tap on "back" button on my NavigationController Here is my code:

hud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:hud];
hud.delegate = self;
hud.labelText = @"Loading...";
[hud show:YES];
Oleg
  • 2,984
  • 8
  • 43
  • 71

3 Answers3

4

You're adding the hud view to the navigation controller - that's why you cannot interact with navigation bar.

What you want to achieve is to lock self.navigationController.topViewController.view which, I think, in your case is accessible via self.view.

Try the following:

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

Let us know if above worked for you. If not, I'll improve the answer to find a solution.

matm
  • 7,059
  • 5
  • 36
  • 50
  • After implementing your answer, HUD is being displayed in different positions depending if I have scrolled my tableView or not. How can I fix that? – Oleg Aug 28 '12 at 11:43
1

Hud will make userIntrection disable...so user unable to touch the area where the hud is add...so just add the hud where you want to add it...but make sure that there in not any UI changes when HUD is Running , because HUD run on secondary thread and changes on secondary thread make your app crash....

    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    HUD.graceTime = .1;
    HUD.labelFont  = [UIFont fontWithName:@"Arial" size:16];
    HUD.labelText = @"Loading..";
    HUD.delegate = self;
    [self.view addSubview:HUD];
    [HUD showWhileExecuting:@selector(loginJsonParsing) onTarget:self withObject:nil animated:YES];
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
0

I used to have this as a bug when the user click on the back button from the navigation bar while the HUD still working in the background BOOM app crush, I managed to fix this with the accepted answer in shorter code. It depends on how custom you want the HUD. I use the default one.

Show:

[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];

Hide:

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
   dispatch_async(dispatch_get_main_queue(), ^{
       [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
   });
});
Ashoor
  • 1,358
  • 1
  • 9
  • 11