iOS: SVProgressHUD doesnt dismiss when user moves from one screen to another in IOS Xcode

2k Views Asked by At

I have used SVProgressHUD for progresshud. I found that SVProgressHUD doesnt dismiss when user moves from one screen to another. Its tedious to call [SVProgressHUD dismiss]; in -(void)viewWillDisappear:(BOOL)animated of every class so i want to find the better solutions. Currently i have implemented below code But I want to find some better methods

-(void)viewWillDisappear:(BOOL)animated{
  [SVProgressHUD dismiss];
}

SVProgressHUD in Git.

I know To dismiss the HUD we need to call one of the following method:

+ (void)dismiss;
+ (void)dismissWithSuccess:(NSString*)successString;
+ (void)dismissWithSuccess:(NSString*)successString afterDelay:(NSTimeInterval)seconds;
+ (void)dismissWithError:(NSString*)errorString;
+ (void)dismissWithError:(NSString*)errorString afterDelay:(NSTimeInterval)seconds;

But I dont want to call [SVProgressHUD dismiss]; in -(void)viewWillDisappear:(BOOL)animated of every class since writing same code in overall projects in each class is not good way of coding

2

There are 2 best solutions below

2
On

You can create a super class where every class that uses the SVProgressHUD inherit that class and in the super class you can do like this :

-(void)viewWillDisappear:(BOOL)animated{
if([SVProgressHUD isVisible]) 
 [SVProgressHUD dismiss];}
0
On

Objective C

Write in AppDelegate.m file.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //add this line
    [SVProgressHUD setDefaultMaskType: SVProgressHUDMaskTypeBlack];
}

This code worked to everywhere in project.