Search code examples
objective-csingletonmbprogresshud

MBProgressHUD to Singleton


I want to set method for showing and dismissing HUD in Singleton. I write this method in singleton:

- (void)showHUD
{
    activityHud = [[MBProgressHUD alloc] init];
    activityHud.delegate = self;
}

but nothing happened. For dismissing, I have no idea how to write... Any answer will be very helpful. Thanks!


Solution

  • Why not use static methods? I use this and put it in my util class.

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

    }

    and hide it with this :

    + (void)dismissGlobalHUD {
    
    [MBProgressHUD hideHUDForView:window animated:YES]; 
    }