将HUD相关方法放到BaseMvpProtocol协议,所有的view都要实现BaseMvpProtocol协议

This commit is contained in:
zu
2021-09-16 17:31:58 +08:00
parent 2932fe03e3
commit 92b97c4747
7 changed files with 30 additions and 36 deletions

View File

@@ -19,7 +19,6 @@ typedef void(^HttpFail)(NSInteger code, NSString * _Nullable msg);
- (void)attatchView:(id)view; - (void)attatchView:(id)view;
- (id)getView; - (id)getView;
- (BaseViewController *)getBaseVC;
- (void)detatchView; - (void)detatchView;
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail; - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail;
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading; - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading;

View File

@@ -23,10 +23,6 @@
return self.view; return self.view;
} }
- (BaseViewController *)getBaseVC {
return ((BaseViewController *) [self getView]);
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail { - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail {
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES]; return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES];
} }
@@ -41,11 +37,11 @@
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast { - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast {
if (loading) { if (loading) {
[[self getBaseVC] showLoading]; [self.view showLoading];
} }
return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) { return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) {
if (loading) { if (loading) {
[[self getBaseVC] hideHUD]; [self.view hideHUD];
} }
if (code == 200) { if (code == 200) {
success(data); success(data);
@@ -62,7 +58,7 @@
} }
if (toast) { if (toast) {
[[self getBaseVC] showErrorToast:msg]; [self.view showErrorToast:msg];
} }
fail(code, msg); fail(code, msg);
}; };

View File

@@ -13,6 +13,25 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tokenInvalid; - (void)tokenInvalid;
- (void)completeUserInfo; - (void)completeUserInfo;
/**
成功 toast
*/
- (void)showSuccessToast:(NSString *)msg;
/**
失败 toast
*/
- (void)showErrorToast:(NSString *)msg;
/**
加载 loading
*/
- (void)showLoading;
/**
隐藏 XCHUDTool
*/
- (void)hideHUD;
@end @end

View File

@@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface MvpViewController<T> : BaseViewController<BaseMvpProtocol> @interface MvpViewController<T> : BaseViewController
@property (nonatomic, strong) __kindof T presenter; @property (nonatomic, strong) __kindof T presenter;

View File

@@ -6,10 +6,11 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "BaseMvpProtocol.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface BaseViewController : UIViewController @interface BaseViewController : UIViewController<BaseMvpProtocol>
// 是否隐藏导航 默认是不隐藏的 // 是否隐藏导航 默认是不隐藏的
@property(nonatomic,assign,getter=isHiddenNavBar) BOOL hiddenNavBar; @property(nonatomic,assign,getter=isHiddenNavBar) BOOL hiddenNavBar;
@@ -36,26 +37,6 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (void)hideStatusBar; - (void)hideStatusBar;
/**
成功 toast
*/
- (void)showSuccessToast:(NSString *)msg;
/**
失败 toast
*/
- (void)showErrorToast:(NSString *)msg;
/**
加载 loading
*/
- (void)showLoading;
/**
隐藏 XCHUDTool
*/
- (void)hideHUD;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@@ -85,7 +85,7 @@
[AccountInfoStorage instance].thirdUserInfo = userInfo; [AccountInfoStorage instance].thirdUserInfo = userInfo;
[Api loginWithThirdPart:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [Api loginWithThirdPart:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getBaseVC] hideHUD]; [[super getView] hideHUD];
AccountModel * model = [AccountModel modelWithDictionary:data.data]; AccountModel * model = [AccountModel modelWithDictionary:data.data];
if (model != nil) { if (model != nil) {
[[AccountInfoStorage instance] saveAccountInfo:model]; [[AccountInfoStorage instance] saveAccountInfo:model];
@@ -94,11 +94,11 @@
} fail:^(NSInteger code, NSString * _Nullable msg) { } fail:^(NSInteger code, NSString * _Nullable msg) {
} showLoading:YES] openid:openid unionid:unionid access_token:access_token type:[NSString stringWithFormat:@"%lu", (unsigned long)type]]; } showLoading:YES] openid:openid unionid:unionid access_token:access_token type:[NSString stringWithFormat:@"%lu", (unsigned long)type]];
} else if(state == SSDKResponseStateCancel) {/// } else if(state == SSDKResponseStateCancel) {///
[[self getBaseVC] hideHUD]; [[super getView] hideHUD];
[[self getBaseVC] showErrorToast:@"登录取消"]; [[super getView] showErrorToast:@"登录取消"];
} else if (state == SSDKResponseStateFail) {/// } else if (state == SSDKResponseStateFail) {///
[[self getBaseVC] hideHUD]; [[super getView] hideHUD];
[[self getBaseVC] showErrorToast:@"登录失败,请重试"]; [[super getView] showErrorToast:@"登录失败,请重试"];
} }
}]; }];
} }

View File

@@ -136,7 +136,6 @@
return nav; return nav;
} }
#pragma mark - main
- (void)showSuccessToast:(NSString *)msg { - (void)showSuccessToast:(NSString *)msg {
[XCHUDTool showSuccessWithMessage:msg]; [XCHUDTool showSuccessWithMessage:msg];
} }