浏览代码

空页面刷新逻辑

Steven 5 年之前
父节点
当前提交
00f4e07021

+ 6 - 0
MusicGradeExam/MusicGradeExam.xcodeproj/project.pbxproj

@@ -348,6 +348,7 @@
 		27A008FE24BECDFC0002452B /* HomeBodyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 27A008FD24BECDFC0002452B /* HomeBodyView.xib */; };
 		27D4149824CA741D000DBC0C /* RecordExamModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D4149724CA741D000DBC0C /* RecordExamModel.m */; };
 		27D4149B24CA757A000DBC0C /* SongModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D4149A24CA757A000DBC0C /* SongModel.m */; };
+		27DBF9D324D8F67B00202145 /* KSStatusView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27DBF9D224D8F67B00202145 /* KSStatusView.m */; };
 		27EF3EEE24BEE35E002068A2 /* MessageListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 27EF3EED24BEE35E002068A2 /* MessageListModel.m */; };
 		27EF3EF224BEE885002068A2 /* NotifyMessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 27EF3EF024BEE885002068A2 /* NotifyMessageCell.m */; };
 		27EF3EF324BEE885002068A2 /* NotifyMessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 27EF3EF124BEE885002068A2 /* NotifyMessageCell.xib */; };
@@ -1024,6 +1025,8 @@
 		27D4149724CA741D000DBC0C /* RecordExamModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecordExamModel.m; sourceTree = "<group>"; };
 		27D4149924CA757A000DBC0C /* SongModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SongModel.h; sourceTree = "<group>"; };
 		27D4149A24CA757A000DBC0C /* SongModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SongModel.m; sourceTree = "<group>"; };
+		27DBF9D124D8F67B00202145 /* KSStatusView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KSStatusView.h; sourceTree = "<group>"; };
+		27DBF9D224D8F67B00202145 /* KSStatusView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KSStatusView.m; sourceTree = "<group>"; };
 		27EF3EEC24BEE35E002068A2 /* MessageListModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageListModel.h; sourceTree = "<group>"; };
 		27EF3EED24BEE35E002068A2 /* MessageListModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageListModel.m; sourceTree = "<group>"; };
 		27EF3EEF24BEE885002068A2 /* NotifyMessageCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NotifyMessageCell.h; sourceTree = "<group>"; };
@@ -2096,6 +2099,8 @@
 				274770F924BC0C0400181362 /* PressRecord */,
 				2747716B24BC0C0400181362 /* StateView.h */,
 				2747717824BC0C0400181362 /* StateView.m */,
+				27DBF9D124D8F67B00202145 /* KSStatusView.h */,
+				27DBF9D224D8F67B00202145 /* KSStatusView.m */,
 				278D114424D0009000599421 /* KSGuideMaskView.h */,
 				278D114524D0009000599421 /* KSGuideMaskView.m */,
 			);
@@ -3089,6 +3094,7 @@
 				274771CD24BC0C0500181362 /* RolePortraitView.m in Sources */,
 				2729F7E724C8326900E1F3C4 /* RecordExamViewController.m in Sources */,
 				2747722024BC0C0500181362 /* UIImage+Property.m in Sources */,
+				27DBF9D324D8F67B00202145 /* KSStatusView.m in Sources */,
 				274771C624BC0C0500181362 /* KSTabBarController.m in Sources */,
 				27D4149824CA741D000DBC0C /* RecordExamModel.m in Sources */,
 				27EF3F2A24C02DE9002068A2 /* EmptyView.m in Sources */,

+ 4 - 2
MusicGradeExam/MusicGradeExam/Base/KSBaseViewController.h

@@ -9,6 +9,7 @@
 #import <UIKit/UIKit.h>
 #import "StateView.h"
 #import "UINavigationController+KSNavigationBar.h"
+#import "KSStatusView.h"
 
 NS_ASSUME_NONNULL_BEGIN
 
@@ -59,8 +60,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)addfeedBackGenertor;//添加震动反馈
 
-- (void)selectBarHomeWithIndex:(NSInteger)index;
-
 -(void)allocTitle:(NSString*)Ntitle withColor:(UIColor *)color;
 - (void)leftWhiteButton;
 
@@ -89,6 +88,9 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)setPromptString:(NSString *)promptString actionRangeString:(NSString *)actionRangeString imageName:(NSString *)imgName inView:(UIView *)view actionBlock:(void (^)(void))actionBlock;
 
+#pragma mark ---- 无数据显示 和回调方法
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName actionTitle:(NSString *)actionTitle inView:(UIView *)view actionBlock:(void (^)(void))actionBlock;
+- (void)changeEmptyStatus;
 #pragma mark - 获取年,月,日,星期 注:日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。
 -(NSInteger )getDataFromDate:(NSDate *)date type:(NSString * )type;
 

+ 33 - 11
MusicGradeExam/MusicGradeExam/Base/KSBaseViewController.m

@@ -25,6 +25,8 @@
 
 @property (nonatomic, strong) UIView *promptPlaceView;
 
+@property (nonatomic, strong) KSStatusView *emptyView;
+
 @end
 
 @implementation KSBaseViewController
@@ -428,12 +430,6 @@
     self.promptView.imageName = imgName;
     self.promptView.alpha = 0.0f;
     [self.promptView setText:promptString];
-
-//    NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:promptString];
-//    att.color = HexRGB(0x999999);
-//    att.font = [UIFont systemFontOfSize:14];
-//    [self.promptView.desLabel setAttributedText:att];
-//    [self.promptView.desLabel sizeToFit];
     [view addSubview:self.promptView];
 }
 
@@ -460,9 +456,6 @@
     [att setTextHighlightRange:range color:THEMECOLOR backgroundColor:[UIColor whiteColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
         actionBlock();
     }];
-    //    [self.promptView.desLabel setHighlightTapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
-    //
-    //    }];
     [self.promptView.desLabel setAttributedText:att];
     [self.promptView.desLabel sizeToFit];
     [view addSubview:self.promptView];
@@ -479,9 +472,38 @@
     
     [UIView animateWithDuration:0.1 animations:^{
         [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
-        
-    }] ;
+    }];
+}
+
+#pragma mark ---- 无数据显示 和回调方法
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName actionTitle:(NSString *)actionTitle inView:(UIView *)view actionBlock:(void (^)(void))actionBlock {
+    if (self.emptyView != nil) {
+        [self.emptyView removeFromSuperview];
+    }
+    else {
+        self.emptyView = [[KSStatusView alloc]init];
+        self.emptyView.frame = view.bounds;
+    }
+    _promptPlaceView = view;
+    //当请求不到数据时 ,自定义提示view 将会出现;
+    [self.emptyView setText:promptString];
+    self.emptyView.imageName = imgName;
+    self.emptyView.alpha = 0.0f;
+    [self.emptyView showButtonAction:actionTitle callback:actionBlock];
+    [view addSubview:self.emptyView];
+}
+
+- (void)changeEmptyStatus {
+    NSInteger count;
+    if (self.dataArray.count) {
+        count = self.dataArray.count;
+    } else {
+        count = 0;
+    }
     
+    [UIView animateWithDuration:0.1 animations:^{
+        [[self emptyView] setAlpha:count ? 0.0f :1.0f ] ;
+    }];
 }
 
 - (void)resetParamenter {

+ 27 - 0
MusicGradeExam/MusicGradeExam/Tools/Custom/KSStatusView.h

@@ -0,0 +1,27 @@
+//
+//  KSStatusView.h
+//  MusicGradeExam
+//
+//  Created by Kyle on 2020/8/4.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+typedef void(^ActionCallback)(void);
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface KSStatusView : UIView
+
+@property (nonatomic, copy) NSString *text;
+
+@property (nonatomic, strong) NSString *imageName;
+
+@property (nonatomic, strong) UILabel *desLabel;
+
+- (void)showButtonAction:(NSString *)buttonTitle callback:(ActionCallback)callback;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 104 - 0
MusicGradeExam/MusicGradeExam/Tools/Custom/KSStatusView.m

@@ -0,0 +1,104 @@
+//
+//  KSStatusView.m
+//  MusicGradeExam
+//
+//  Created by Kyle on 2020/8/4.
+//  Copyright © 2020 DayaMusic. All rights reserved.
+//
+
+#import "KSStatusView.h"
+
+@interface KSStatusView ()
+{
+    UIImageView *_imgView;
+}
+
+@property (nonatomic, strong) UIButton *actionButton;
+
+@property (nonatomic, copy) ActionCallback callback;
+
+@end
+
+@implementation KSStatusView
+
+- (instancetype)init {
+    self = [super init];
+    if (self) {
+        _desLabel = [[UILabel alloc] init];
+        _desLabel.font = [UIFont systemFontOfSize:17.0f];
+        _desLabel.textColor = HexRGB(0x999999);
+        _desLabel.textAlignment = NSTextAlignmentCenter;
+        _desLabel.numberOfLines = 1;
+        [self addSubview:_desLabel];
+        
+        _imgView = [[UIImageView alloc] init];
+        [_imgView sizeToFit];
+        [self addSubview:_imgView];
+    }
+    return self;
+}
+
+-(void)layoutSubviews
+{
+    _desLabel.center = CGPointMake(self.center.x, self.center.y);
+    _imgView.center = CGPointMake(self.center.x, self.center.y - 130);
+    _actionButton.center = CGPointMake(self.center.x, CGRectGetMaxY(self.desLabel.frame)+30);
+}
+
+-(void)setText:(NSString *)strText
+{
+    _desLabel.text = strText;
+    [_desLabel sizeToFit];
+}
+
+- (void)setImageName:(NSString *)imageName {
+    _imageName = imageName;
+    [_imgView setImage:[UIImage imageNamed:imageName]];
+    [_imgView sizeToFit];
+}
+
+- (void)showButtonAction:(NSString *)buttonTitle callback:(ActionCallback)callback {
+    if (callback) {
+        self.callback = callback;
+    }
+    CGFloat width = [self getButtonWidth:buttonTitle];
+    if (_actionButton) {
+        [_actionButton removeFromSuperview];
+        [_actionButton setTitle:buttonTitle forState:UIControlStateNormal];
+        _actionButton.frame = CGRectMake(0, 0, width, 30);
+        [self addSubview:_actionButton];
+    }
+    else {
+        _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
+        [_actionButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
+        [_actionButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
+        [_actionButton setTitle:buttonTitle forState:UIControlStateNormal];
+        _actionButton.frame = CGRectMake(0, 0, width, 30);
+        _actionButton.layer.cornerRadius = 15.0f;
+        _actionButton.layer.borderWidth = 1.0f;
+        _actionButton.layer.borderColor = THEMECOLOR.CGColor;
+        [_actionButton addTarget:self action:@selector(buttonClickAction) forControlEvents:UIControlEventTouchUpInside];
+        [self addSubview:_actionButton];
+    }
+    
+}
+
+- (CGFloat)getButtonWidth:(NSString *)buttonTitle {
+    return [buttonTitle boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0f]} context:nil].size.width + 24;
+}
+
+- (void)buttonClickAction {
+    if (self.callback) {
+        self.callback();
+    }
+}
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 13 - 8
MusicGradeExam/MusicGradeExam/UI/ExamLibrary/Controller/ExamLibraryController.m

@@ -124,7 +124,10 @@
     self.rows = 10;
     self.dataArray = [NSMutableArray array];
     [self.tableView.mj_footer resetNoMoreData];
-    [self setPromptString:@"暂无曲目" imageName:@"empty_library" inView:self.tableView];
+    MJWeakSelf;
+    [self setPromptString:@"暂无曲目" imageName:@"empty_library" actionTitle:@"返回" inView:self.tableView actionBlock:^{
+        [weakSelf.navigationController popViewControllerAnimated:YES];
+    }];
     [self.tableView reloadData];
 }
 
@@ -147,16 +150,20 @@
             [self MBPShow:MESSAGEKEY];
         }
         
-        [self changePromptLabelState];
+        [self changeEmptyStatus];
     } faliure:^(NSError * _Nonnull error) {
         [self.tableView.mj_header endRefreshing];
         [self.tableView.mj_footer endRefreshing];
         if (self.networkAvaiable == NO) {
-            [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" inView:self.tableView];
+            MJWeakSelf;
+            [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" actionTitle:@"刷新一下" inView:self.tableView actionBlock:^{
+                [weakSelf resetParamenter];
+                [weakSelf requestData];
+            }];
         }
         [self.dataArray removeAllObjects];
         [self.tableView reloadData];
-        [self changePromptLabelState];
+        [self changeEmptyStatus];
     }];
 }
 
@@ -192,11 +199,9 @@
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     SongListModel *model = self.dataArray[indexPath.row];
     if ([NSString isEmptyString:model.fileUrlList]) {
-//        [self MBPShow:@"曲库链接错误"];
-//        return;
-        model.fileUrlList = @"https://www.tutorialspoint.com/ios/ios_tutorial.pdf";
+        [self MBPShow:@"曲库链接错误"];
+        return;
     }
-//    model.fileUrlList = @"https://www.tutorialspoint.com/ios/ios_tutorial.pdf";
     OpenFileViewController *readCtrl = [[OpenFileViewController alloc] init];
     readCtrl.urlString = model.fileUrlList;
     readCtrl.fileName = model.songName;

+ 27 - 0
MusicGradeExam/MusicGradeExam/UI/ExamLibrary/Controller/ExamViewController.m

@@ -38,10 +38,20 @@
     [self requestData];
 }
 
+
+- (void)resetParamenter {
+    self.dataArray = [NSMutableArray array];
+    MJWeakSelf;
+    [self setPromptString:@"暂无考级信息" imageName:@"empty_library" actionTitle:@"返回" inView:self.tableView actionBlock:^{
+        [weakSelf.navigationController popViewControllerAnimated:YES];
+    }];
+}
+
 - (void)requestData {
     [self showhud];
     [KSRequestManager studentBaseExamsRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
         [self removehub];
+        [self.tableView.mj_header endRefreshing];
         if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
             NSArray *source = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
             NSMutableArray *sourceArray = [NSMutableArray array];
@@ -55,8 +65,20 @@
         else {
             [self MBPShow:MESSAGEKEY];
         }
+        [self changeEmptyStatus];
     } faliure:^(NSError * _Nonnull error) {
         [self removehub];
+        [self.tableView.mj_header endRefreshing];
+        if (self.networkAvaiable == NO) {
+            MJWeakSelf;
+            [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" actionTitle:@"刷新一下" inView:self.tableView actionBlock:^{
+                [weakSelf resetParamenter];
+                [weakSelf requestData];
+            }];
+        }
+        [self.dataArray removeAllObjects];
+        [self.tableView reloadData];
+        [self changeEmptyStatus];
     }];
 }
 
@@ -64,6 +86,11 @@
     [self.scrollView removeFromSuperview];
     [self.view addSubview:self.tipsView];
     [self.view addSubview:self.tableView];
+    MJWeakSelf;
+    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
+        [weakSelf resetParamenter];
+        [weakSelf requestData];
+    }];
 }
 
 

+ 11 - 5
MusicGradeExam/MusicGradeExam/UI/NotiferMessage/Controller/NotifyMessageViewController.m

@@ -60,24 +60,27 @@
         else {
             [self MBPShow:MESSAGEKEY];
         }
-        [self changePromptLabelState];
+        [self changeEmptyStatus];
     } faliure:^(NSError * _Nonnull error) {
         [self removehub];
         [self.tableView.mj_header endRefreshing];
         [self.tableView.mj_footer endRefreshing];
         if (self.networkAvaiable == NO) {
-            [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" inView:self.tableView];
+            MJWeakSelf;
+            [self setPromptString:@"网络开小差,再刷新看看" imageName:@"networking_error" actionTitle:@"刷新一下" inView:self.tableView actionBlock:^{
+                [weakSelf resetParamenter];
+                [weakSelf requestData];
+            }];
         }
         [self.dataArray removeAllObjects];
         [self.tableView reloadData];
-        [self changePromptLabelState];
+        [self changeEmptyStatus];
     }];
 }
 
 
 - (void)configUI {
     [self.view addSubview:self.tableView];
-    [self setPromptString:@"暂无消息" imageName:@"empty_message" inView:self.tableView];
     MJWeakSelf;
     self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
         [weakSelf resetParamenter];
@@ -100,7 +103,10 @@
     self.rows = 10;
     self.dataArray = [NSMutableArray array];
     [self.tableView.mj_footer resetNoMoreData];
-    [self setPromptString:@"暂无消息" imageName:@"empty_message" inView:self.tableView];
+    MJWeakSelf;
+    [self setPromptString:@"暂无消息" imageName:@"empty_message" actionTitle:@"返回" inView:self.tableView actionBlock:^{
+        [weakSelf.navigationController popViewControllerAnimated:YES];
+    }];
     [self.tableView reloadData];
 }