title: Reusable MBProgressHUD
body: <p>I want to make a "reusable" MBProgressHUD. For example, I have a code mostly like this.</p>
  
  <pre><code>- (void)viewDidLoad {
      HUD = [[MBProgressHUD alloc] init];
      HUD.delegate = self;
  
      [self functionOne];
  }
  
  - (void)functionOne {
      //turn on HUD
      HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
      HUD.labelText = @"Loading with message 1";
  
      NSURLSessionDataTask *dataTask = [defaultSession 
          dataTaskWithRequest:urlRequest 
          completionHandler:^(NSData *dataRaw, NSURLResponse *header, NSError *error) 
              {
                  //on completion turn off HUD and call functionTwo
                  [HUD show:NO];
                  [self functionTwo];
              }
      ];
  }
  
  - (void)functionTwo {
      //turn on again THE SAME HUD
      HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
      HUD.labelText = @"Loading with message 2";
  
      NSURLSessionDataTask *dataTask = [defaultSession 
          dataTaskWithRequest:urlRequest 
          completionHandler:^(NSData *dataRaw, NSURLResponse *header, NSError *error) 
              {
                  //on completion turn off THE SAME HUD
                  [HUD show:NO];
              }
      ];
  }
  </code></pre>
  
  <p>The problem is the code crash on <code>//turn on again THE SAME HUD</code> with error:</p>
  
  <blockquote>
    <p>Assertion failure in -[MBProgressHUD initWithView:] - Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'View must not be nil.'</p>
  </blockquote>
  
  <p>I dont know why, specially if I alloc and init it in viewDidLoad.</p>
  
  <p>Another things is I don't understand the difference between <code>[HUD hide:YES]</code> and <code>[HUD show:NO]</code></p>
  
  <p>EDIT: this is my original code.</p>
  
  <pre><code>@implementation ReservasViewController
  {
  NSMutableArray *arrayPartidos;
  MBProgressHUD *HUD;
  NSInteger idPartidoEstado;
  }
  
  - (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  [[self navigationController] setNavigationBarHidden:NO animated:NO];
  self.navigationController.navigationBarHidden = NO;
  self.navigationController.navigationBar.hidden = NO;
  
  [self obtenerPartidosJugador];
  }
  
  -(void)obtenerPartidosJugador
  {
  HUD = [[MBProgressHUD alloc] init];
  HUD.delegate = self;
  HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  HUD.labelText = @"Cargando partidos...";
  
  //----------------------
  NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
  NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
  
  NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%s%s", root_server, obtener_reservas]];
  NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
  [urlRequest setHTTPMethod:@"POST"];
  
  NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *dataRaw, NSURLResponse *header, NSError *error) {
  
      NSDictionary *respServidor = [NSJSONSerialization JSONObjectWithData:dataRaw options:0 error:&amp;error];
      NSLog(@"respServidor %@", respServidor);
  
      if(!error){
  
          if([[respServidor valueForKey:@"status"]  isEqual: @"true"]){
  
              arrayPartidos = [[NSMutableArray alloc] init];
              arrayPartidos = [[respServidor objectForKey:@"partidos"] mutableCopy];
  
              [self.tableView reloadData];
  
          }else{
              arrayPartidos = nil;
          }
  
      } else {
          NSLog(@"error --&gt; %@", error);
      }
  
      [HUD hide:YES];
      [HUD show:NO];
  
  }];
  
  [dataTask resume];
  }
  
  //this function is called by a IBAction
  -(void)cambiarEstadoPartido:(NSInteger)estado idPartido:(NSInteger)idpartido
  {
  HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
  HUD.labelText = @"Actualizando...";
  
  NSString *noteDataString = [NSString stringWithFormat:@"estado=%ld&amp;idpartido=%ld", estado, idpartido];
  //----------------------
  NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
  NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
  
  NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%s%s", root_server, cambiar_estado_partido]];
  NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
  [urlRequest setHTTPMethod:@"POST"];
  [urlRequest setHTTPBody:[noteDataString dataUsingEncoding:NSUTF8StringEncoding]];
  
  NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *dataRaw, NSURLResponse *header, NSError *error) {
  
      NSDictionary *respServ = [NSJSONSerialization JSONObjectWithData:dataRaw options:0 error:&amp;error];
      NSLog(@"respServidor %@", respServ);
  
      if(!error){
  
          if([[respServ valueForKey:@"status"]  isEqual: @"true"]){
  
              [HUD hide:YES];
              [HUD show:NO];
  
              [self obtenerPartidosJugador];
  
          }else{
  
              [HUD hide:YES];
              [HUD show:NO];
  
              UIAlertView *alertConfirm = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Ocurrio un error, vuelve a intentarlo" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
              alertConfirm.tag = 0;
              [alertConfirm show];
  
          }
  
      } else {
  
          [HUD hide:YES];
          [HUD show:NO];
  
          NSLog(@"error --&gt; %@", error);
          UIAlertView *alertConfirm = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Ocurrio un error, vuelve a intentarlo" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
          alertConfirm.tag = 0;
          [alertConfirm show];
  
      }
  
  }];
  
  [dataTask resume];
  }
  </code></pre>
  
  <p>EDIT 2: i remove all the lines that refer to the MBProgressHUD, i also remove the #import and the delegate but im still having that fu***ng error!
  <a href="https://i.stack.imgur.com/LwpjC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LwpjC.png" alt="enter image description here"></a></p>