2015-05-04 67 views
0

no sign of networkI want to add MBProgressHUD to a queue, if the queue has MBProgressHUD show, do not add MBProgressHUD to this queue, if the queue is not MBProgressHUD display is added to the queue.How to add MBProgressHUD to a queue

Chinese Version: 我想添加MBProgressHUD到一個隊列中,如果這個隊列中有MBProgressHUD顯示,就不要添加MBProgressHUD到這個隊列中,如果這個隊列中沒有MBProgressHUD顯示則添加到這個隊列中

Here is my code, but I can still see the display lots MBProgressHUD, and they are superimposed together, and will not disappear

+ (void)showErrorHUD:(id)target withText:(NSString *)text{ 
    MBProgressHUD *errorHud = nil; 
    if ([target isKindOfClass:[UIViewController class]]) { 
     errorHud = [MBProgressHUD showHUDAddedTo:[target view] animated:YES]; 
    } 
    else if([target isKindOfClass:[UIWindow class]]){  
     errorHud = [MBProgressHUD showHUDAddedTo:target animated:YES]; 
    } 
    errorHud.userInteractionEnabled = NO;// errorHud的下層視圖可以響應 
    errorHud.mode = MBProgressHUDModeCustomView; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_red_x"]]; 
    errorHud.labelText = text; 
    errorHud.labelColor = REDCOLOR; 
    errorHud.customView = imageView; 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ 
     sleep(1); 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [MBProgressHUD hideHUDForView:[target isKindOfClass:[UIWindow class]] ? target : [target view] animated:YES]; 
     }); 
    }); 
} 

In the phone without a network, APP will start when invoking multiple network interfaces, then performs the following methods to show no sign of network

[self showErrorHUD:[UIApplication sharedApplication].keyWindow withText:@"no network"]; 
+0

What are you asking? It's completely unclear as to what you want to accomplish. – barndog

+0

Update your question. can not understand what you trying to do. –

+0

sorry everyone my English is poor, I've updated the question – lingchen

回答

1

In the description of all is https://github.com/jdg/MBProgressHUD

[MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ 
    // Do something... 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [MBProgressHUD hideHUDForView:self.view animated:YES]; 
    }); 
}); 
+0

Thank you for you answer. I've updated the question, Your answer seems not solve my problem. – lingchen