Search code examples
iphoneobjective-cuiprogressbar

Disabled touch when UIProgressBarHUD is shown


I've created an app where I'm creating a UIProgressBarHUD to show that something is loading. My question is, how can I disable the view so nothing can be pressed untill the loading is finished?

I've tried setting:

[self.view setUserInterationEnabled:NO];

However this doesn't work :/

Here is the code I'm using for adding the UIProgressHUD:

- (IBAction) showHUD:(id)sender
{
       //[self.view setUserInteractionEnabled:NO];

       UIProgressHUD *HUD = [[UIProgressHUD alloc]
initWithWindow:[[UIApplication sharedApplication] keyWindow]];
       [HUD setText:@"Loading…"];
       [HUD show:YES];

       [HUD performSelector:@selector(done) withObject:nil afterDelay:1.5];
       [HUD performSelector:@selector(setText:) withObject:@"Done!"
afterDelay:1.5];
       [HUD performSelector:@selector(hide) withObject:nil afterDelay:4.0];

       //[self.view setUserInteractionEnabled:YES];

       [HUD release];
}

Any help would be muchly appreciated!! - James


Solution

  • As pointed out here, UIProgressHUD is private. You should not use it.

    There is a library that gives you what you are looking for though.

    It allows you to keep the user from tapping anything while it is updating as you requested.