Use of MBProgressHUD Globally + make it singleton

后端 未结 9 1207
时光说笑
时光说笑 2020-12-23 02:06

In my Project, each of the user interaction events make a network call (Which is TCP, not HTTP). I need Activity Indicator to be global to show from a rando

9条回答
  •  遥遥无期
    2020-12-23 02:15

    I've used it as below..Hope it helps you..

    in appDelegate.m

    -(void)showIndicator:(NSString *)withTitleString currentView:(UIView *)currentView
    { 
    if (!isIndicatorStarted) {
    
        // The hud will dispable all input on the view
        self.progressHUD = [[[MBProgressHUD alloc] initWithView:currentView] autorelease]; 
        // Add HUD to screen 
        [currentView addSubview:self.progressHUD]; 
        self.progressHUD.labelText = withTitleString;
        [window setUserInteractionEnabled:FALSE];
        [self.progressHUD show:YES];
    
        isIndicatorStarted = TRUE;
    }   
     } 
    
    -(void)hideIndicator 
    { 
    
        [self.progressHUD show:NO]; 
        [self.progressHUD removeFromSuperview]; 
        self.progressHUD = nil;
        [window setUserInteractionEnabled:TRUE];
        isIndicatorStarted = FALSE;
    }
    

    From Random Views:-

    [appDel showIndicator:@"Loading.." currentView:presentView.view];

提交回复
热议问题