Search code examples
iphoneobjective-cxcodecocoa-touchmbprogresshud

iphone - MBProgressHUD prevent locking navigationController


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];

Solution

  • 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.