Use of MBProgressHUD Globally + make it singleton

后端 未结 9 1198
时光说笑
时光说笑 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

    This answer is what I've been using for 5-6 Apps now because it works perfectly inside blocks too. However I found a problem with it. I can make it shown, but can't make it disappear if a UIAlertView is also present. If you look at the implementation you can see why. Simply change it to this:

    static UIWindow *window;
    
    + (MBProgressHUD *)showGlobalProgressHUDWithTitle:(NSString *)title {
    
        window = [[[UIApplication sharedApplication] windows] lastObject];
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
        hud.labelText = title;
    
        return hud;
    }
    
    + (void)dismissGlobalHUD {
    
        [MBProgressHUD hideHUDForView:window animated:YES];
    }
    

    This will make sure you're removing the HUD from the same windows as it was shown on.

提交回复
热议问题