问题
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
回答1:
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];}
回答2:
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.
来源:https://stackoverflow.com/questions/30642980/ios-svprogresshud-doesnt-dismiss-when-user-moves-from-one-screen-to-another-in