2

someone uses MBProgressHUD ? I want to use the animation showWithLabelMixed in the example provided with MBProgressHUD librairie. i copied this code from the exemple to my project .

-(IBAction)showActivity:(id)sender
{
    NSLog(@"Show Activity");
    [self showWithLabelMixed];

}

- (void)showWithLabelMixed{

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

    HUD.delegate = self;
    HUD.labelText = @"Conecting";
    HUD.minSize = CGSizeMake(135.f, 135.f);

    [HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
}


- (void)myTask {
    // Do something usefull in here instead of sleeping ...
    sleep(3);
}

- (void)myProgressTask {
    // This just increases the progress indicator in a loop
    float progress = 0.0f;
    while (progress < 1.0f) {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
}




- (void)myMixedTask {
    // Indeterminate mode
    sleep(2);
    // Switch to determinate mode
    HUD.mode = MBProgressHUDModeDeterminate;
    HUD.labelText = @"Progress";
    float progress = 0.0f;
    while (progress < 1.0f)
    {
        progress += 0.01f;
        HUD.progress = progress;
        usleep(50000);
    }
    // Back to indeterminate mode
    HUD.mode = MBProgressHUDModeIndeterminate;
    HUD.labelText = @"Cleaning up";
    sleep(2);
    // The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
    // Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
    HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
    HUD.mode = MBProgressHUDModeCustomView;
    HUD.labelText = @"Completed";
    sleep(2);
}

But i have a crash

Terminating app due to uncaught exception 'MBProgressHUDViewIsNillException', reason: 'The view used in the MBProgressHUD initializer is nil.' can you help me please ?

Keviin55
  • 117
  • 3
  • 11

1 Answers1

2

The view which you're initializing the HUD with is nil Try initializing it with

[[UIApplication sharedApplication] keyWindow]
DanZimm
  • 2,528
  • 2
  • 19
  • 27
  • @DDanZimm Oh it's true I have no navbarcontroller, I use tabBarController .I change the initialization to HUD = [[MBProgressHUD alloc] initWithView:self.tabBarController.view]; , and HUD = [[MBProgressHUD alloc] initWithView:self.view]; in both cases I have not error but nothing appears . how to use the initialization you given me ? – Keviin55 Nov 24 '11 at 15:01
  • i have to make this HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; – Keviin55 Nov 24 '11 at 15:38
  • glad to hear you found your problem! happy thanksgiving if youre in america! – DanZimm Nov 24 '11 at 15:43