Commit 45226fe0 cgx

完善我的添加图片网络异常处理

1 个父辈 ec2ed233
...@@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,7 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
// 异常处理类型 // 异常处理类型
typedef NS_ENUM(NSInteger, ExceptionType) { typedef NS_ENUM(NSInteger, ExceptionType) {
ExceptionTypeNet ExceptionTypeNet,
ExceptionTypeSmall
}; };
// 处理事件回调 // 处理事件回调
......
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
self.hidden = YES; self.hidden = YES;
[superView addSubview:self]; [superView addSubview:self];
[self addSubview:self.exceptionIV];
[self addSubview:self.exceptLab]; [self addSubview:self.exceptLab];
[self addSubview:self.dealBtn]; [self addSubview:self.dealBtn];
if (type == ExceptionTypeNet) {
[self addSubview:self.exceptionIV];
[self mas_makeConstraints:^(MASConstraintMaker *make) { [self mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(superView); make.left.right.equalTo(superView);
make.center.equalTo(superView); make.center.equalTo(superView);
...@@ -49,6 +51,22 @@ ...@@ -49,6 +51,22 @@
make.top.equalTo(self.exceptLab.mas_bottom).offset(42); make.top.equalTo(self.exceptLab.mas_bottom).offset(42);
make.bottom.equalTo(self).offset(-30); make.bottom.equalTo(self).offset(-30);
}]; }];
} else if (type == ExceptionTypeSmall) {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.bottom.right.equalTo(superView);
}];
[self.exceptLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.left.equalTo(self).offset(5);
make.right.equalTo(self).offset(-5);
make.centerY.equalTo(self).offset(-30);
}];
[self.dealBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.size.mas_equalTo(CGSizeMake(155, 40));
make.centerY.equalTo(self).offset(30);
}];
}
} }
return self; return self;
} }
...@@ -89,6 +107,8 @@ ...@@ -89,6 +107,8 @@
NSString *info = @""; NSString *info = @"";
if (type == ExceptionTypeNet) { if (type == ExceptionTypeNet) {
info = @"当前网络环境较差,点击刷新重新加载~"; info = @"当前网络环境较差,点击刷新重新加载~";
} else if (type == ExceptionTypeSmall) {
info = @"当前网络环境较差,点击刷新重新加载~";
} }
return info; return info;
} }
...@@ -97,6 +117,8 @@ ...@@ -97,6 +117,8 @@
NSString *title = @""; NSString *title = @"";
if (type == ExceptionTypeNet) { if (type == ExceptionTypeNet) {
title = @"刷新"; title = @"刷新";
} else if (type == ExceptionTypeSmall) {
title = @"刷新";
} }
return title; return title;
} }
......
...@@ -128,6 +128,7 @@ ...@@ -128,6 +128,7 @@
@property (nonatomic, strong) UIView *footerView; @property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) UIImageView *introduceIV; @property (nonatomic, strong) UIImageView *introduceIV;
@property (nonatomic, strong) NSURL *introduceUrl; @property (nonatomic, strong) NSURL *introduceUrl;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView;
@end @end
@implementation ProfileTableView @implementation ProfileTableView
...@@ -145,14 +146,7 @@ ...@@ -145,14 +146,7 @@
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[self registerClass:[ProfileCell class] forCellReuseIdentifier:NSStringFromClass([ProfileCell class])]; [self registerClass:[ProfileCell class] forCellReuseIdentifier:NSStringFromClass([ProfileCell class])];
WS(weakSelf);
self.introduceUrl = [NSURL URLWithString:@"https://img2.ydniu.com/sleep_ssmain/cbti_cover.png"];
self.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
[weakSelf.introduceIV yy_setImageWithURL:self.introduceUrl placeholder:[UIImage imageNamed:@"bannerPlaceholder"] options:YYWebImageOptionShowNetworkActivity completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
[weakSelf.mj_header endRefreshing];
if (error) { [DSProgressHUD showToast:@"网络异常,请稍候重试"]; }
}];
}];
} }
return self; return self;
} }
...@@ -262,13 +256,33 @@ ...@@ -262,13 +256,33 @@
UIImageView *introduceIV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, width, height)]; UIImageView *introduceIV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, width, height)];
[introduceIV cornerRadius:12.0]; [introduceIV cornerRadius:12.0];
introduceIV.userInteractionEnabled = YES; introduceIV.userInteractionEnabled = YES;
[introduceIV yy_setImageWithURL:self.introduceUrl placeholder:[UIImage imageNamed:@"bannerPlaceholder"]];
[_footerView addSubview:introduceIV]; [_footerView addSubview:introduceIV];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCBTIAction)]; UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCBTIAction)];
[introduceIV addGestureRecognizer:tapGR]; [introduceIV addGestureRecognizer:tapGR];
self.introduceIV = introduceIV; self.introduceIV = introduceIV;
[self loadImg];
} }
return _footerView; return _footerView;
} }
- (ExceptionDefaultView *)exceptionView {
if (!_exceptionView) {
WS(weakSelf);
_exceptionView = [[ExceptionDefaultView alloc] initWithType:ExceptionTypeSmall block:^{
weakSelf.exceptionView.hidden = YES;
[weakSelf loadImg];
} superView:self.footerView];
}
return _exceptionView;
}
- (void)loadImg {
WS(weakSelf);
[self.introduceIV yy_setImageWithURL:[NSURL URLWithString:@"https://img2.ydniu.com/sleep_ssmain/cbti_cover.png"] placeholder:[UIImage imageNamed:@"bannerPlaceholder"] options:YYWebImageOptionShowNetworkActivity completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
weakSelf.exceptionView.hidden = error ? NO : YES;
weakSelf.introduceIV.hidden = !weakSelf.exceptionView.hidden;
}];
}
@end @end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!