├── .gitignore ├── Demo.gif ├── README.md └── XYTableViewNoDataViewDemo ├── XYTableViewNoDataView ├── UICollectionView+XY.h ├── UICollectionView+XY.m ├── UITableView+XY.h ├── UITableView+XY.m ├── XYNoDataView.h └── XYNoDataView.m ├── XYTableViewNoDataViewDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── XYTableViewNoDataViewDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json └── note_list_no_data.imageset │ ├── Contents.json │ └── 笔记.png ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── MJRefresh ├── Base │ ├── MJRefreshAutoFooter.h │ ├── MJRefreshAutoFooter.m │ ├── MJRefreshBackFooter.h │ ├── MJRefreshBackFooter.m │ ├── MJRefreshComponent.h │ ├── MJRefreshComponent.m │ ├── MJRefreshFooter.h │ ├── MJRefreshFooter.m │ ├── MJRefreshHeader.h │ └── MJRefreshHeader.m ├── Custom │ ├── Footer │ │ ├── Auto │ │ │ ├── MJRefreshAutoGifFooter.h │ │ │ ├── MJRefreshAutoGifFooter.m │ │ │ ├── MJRefreshAutoNormalFooter.h │ │ │ ├── MJRefreshAutoNormalFooter.m │ │ │ ├── MJRefreshAutoStateFooter.h │ │ │ └── MJRefreshAutoStateFooter.m │ │ └── Back │ │ │ ├── MJRefreshBackGifFooter.h │ │ │ ├── MJRefreshBackGifFooter.m │ │ │ ├── MJRefreshBackNormalFooter.h │ │ │ ├── MJRefreshBackNormalFooter.m │ │ │ ├── MJRefreshBackStateFooter.h │ │ │ └── MJRefreshBackStateFooter.m │ └── Header │ │ ├── MJRefreshGifHeader.h │ │ ├── MJRefreshGifHeader.m │ │ ├── MJRefreshNormalHeader.h │ │ ├── MJRefreshNormalHeader.m │ │ ├── MJRefreshStateHeader.h │ │ └── MJRefreshStateHeader.m ├── MJRefresh.bundle │ ├── arrow@2x.png │ ├── en.lproj │ │ └── Localizable.strings │ ├── zh-Hans.lproj │ │ └── Localizable.strings │ └── zh-Hant.lproj │ │ └── Localizable.strings ├── MJRefresh.h ├── MJRefreshConst.h ├── MJRefreshConst.m ├── NSBundle+MJRefresh.h ├── NSBundle+MJRefresh.m ├── UIScrollView+MJExtension.h ├── UIScrollView+MJExtension.m ├── UIScrollView+MJRefresh.h ├── UIScrollView+MJRefresh.m ├── UIView+MJExtension.h └── UIView+MJExtension.m ├── ViewController.h ├── ViewController.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | # CocoaPods 32 | # 33 | # We recommend against adding the Pods directory to your .gitignore. However 34 | # you should judge for yourself, the pros and cons are mentioned at: 35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 36 | # 37 | # Pods/ 38 | 39 | # Carthage 40 | # 41 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 42 | # Carthage/Checkouts 43 | 44 | Carthage/Build 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 52 | 53 | fastlane/report.xml 54 | fastlane/Preview.html 55 | fastlane/screenshots 56 | fastlane/test_output 57 | 58 | # Code Injection 59 | # 60 | # After new code Injection tools there's a generated folder /iOSInjectionProject 61 | # https://github.com/johnno1962/injectionforxcode 62 | 63 | iOSInjectionProject/ 64 | -------------------------------------------------------------------------------- /Demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanyx1992/XYTableViewNoDataView/e7de96f22c30959dae5b2146f19cb9f6973af7a2/Demo.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XYTableViewNoDataView 2 | 0行代码实现 TableView 和 CollectionView 无数据时 展示一个占位视图 3 | 4 | [查看思路](http://www.jianshu.com/p/246b445ec4e3) 5 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/UICollectionView+XY.h: -------------------------------------------------------------------------------- 1 | // 2 | // UICollectionView+XY.h 3 | // XYTableViewNoDataView 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 iCourt. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UICollectionView (XY) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/UICollectionView+XY.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XY.m 3 | // XYTableViewNoDataView 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 iCourt. All rights reserved. 7 | // 8 | 9 | #import "UICollectionView+XY.h" 10 | #import "XYNoDataView.h" 11 | #import 12 | 13 | /** 14 | 消除警告 15 | */ 16 | @protocol XYTableViewDelegate 17 | @optional 18 | - (UIView *)xy_noDataView; // 完全自定义占位图 19 | - (UIImage *)xy_noDataViewImage; // 使用默认占位图, 提供一张图片, 可不提供, 默认不显示 20 | - (NSString *)xy_noDataViewMessage; // 使用默认占位图, 提供显示文字, 可不提供, 默认为暂无数据 21 | - (UIColor *)xy_noDataViewMessageColor; // 使用默认占位图, 提供显示文字颜色, 可不提供, 默认为灰色 22 | - (NSNumber *)xy_noDataViewCenterYOffset; // 使用默认占位图, CenterY 向下的偏移量 23 | @end 24 | 25 | 26 | @implementation UICollectionView (XY) 27 | 28 | /** 29 | 加载时, 交换方法 30 | */ 31 | + (void)load { 32 | // 只交换一次 33 | static dispatch_once_t onceToken; 34 | dispatch_once(&onceToken, ^{ 35 | 36 | Method reloadData = class_getInstanceMethod(self, @selector(reloadData)); 37 | Method xy_reloadData = class_getInstanceMethod(self, @selector(xy_reloadData)); 38 | method_exchangeImplementations(reloadData, xy_reloadData); 39 | 40 | Method dealloc = class_getInstanceMethod(self, NSSelectorFromString(@"dealloc")); 41 | Method xy_dealloc = class_getInstanceMethod(self, @selector(xy_dealloc)); 42 | method_exchangeImplementations(dealloc, xy_dealloc); 43 | }); 44 | } 45 | 46 | /** 47 | 在 ReloadData 的时候检查数据 48 | */ 49 | - (void)xy_reloadData { 50 | 51 | [self xy_reloadData]; 52 | 53 | // 忽略第一次加载 54 | if (![self isInitFinish]) { 55 | [self xy_havingData:YES]; 56 | [self setIsInitFinish:YES]; 57 | return ; 58 | } 59 | // 刷新完成之后检测数据量 60 | dispatch_async(dispatch_get_main_queue(), ^{ 61 | 62 | NSInteger numberOfSections = [self numberOfSections]; 63 | BOOL havingData = NO; 64 | for (NSInteger i = 0; i < numberOfSections; i++) { 65 | if ([self numberOfItemsInSection:i] > 0) { 66 | havingData = YES; 67 | break; 68 | } 69 | } 70 | 71 | [self xy_havingData:havingData]; 72 | }); 73 | } 74 | 75 | /** 76 | 展示占位图 77 | */ 78 | - (void)xy_havingData:(BOOL)havingData { 79 | 80 | // 不需要显示占位图 81 | if (havingData) { 82 | [self freeNoDataViewIfNeeded]; 83 | self.backgroundView = nil; 84 | return ; 85 | } 86 | 87 | // 不需要重复创建 88 | if (self.backgroundView) { 89 | return ; 90 | } 91 | 92 | // 自定义了占位图 93 | if ([self.delegate respondsToSelector:@selector(xy_noDataView)]) { 94 | self.backgroundView = [self.delegate performSelector:@selector(xy_noDataView)]; 95 | return ; 96 | } 97 | 98 | // 使用自带的 99 | UIImage *img = nil; 100 | NSString *msg = @"暂无数据"; 101 | UIColor *color = [UIColor lightGrayColor]; 102 | CGFloat offset = 0; 103 | 104 | // 获取图片 105 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewImage)]) { 106 | img = [self.delegate performSelector:@selector(xy_noDataViewImage)]; 107 | } 108 | // 获取文字 109 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewMessage)]) { 110 | msg = [self.delegate performSelector:@selector(xy_noDataViewMessage)]; 111 | } 112 | // 获取颜色 113 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewMessageColor)]) { 114 | color = [self.delegate performSelector:@selector(xy_noDataViewMessageColor)]; 115 | } 116 | // 获取偏移量 117 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewCenterYOffset)]) { 118 | offset = [[self.delegate performSelector:@selector(xy_noDataViewCenterYOffset)] floatValue]; 119 | } 120 | 121 | // 创建占位图 122 | self.backgroundView = [self xy_defaultNoDataViewWithImage :img message:msg color:color offsetY:offset]; 123 | } 124 | 125 | /** 126 | 默认的占位图 127 | */ 128 | - (UIView *)xy_defaultNoDataViewWithImage:(UIImage *)image message:(NSString *)message color:(UIColor *)color offsetY:(CGFloat)offset { 129 | 130 | // 计算位置, 垂直居中, 图片默认中心偏上. 131 | CGFloat sW = self.bounds.size.width; 132 | CGFloat cX = sW / 2; 133 | CGFloat cY = self.bounds.size.height * (1 - 0.618) + offset; 134 | CGFloat iW = image.size.width; 135 | CGFloat iH = image.size.height; 136 | 137 | // 图片 138 | UIImageView *imgView = [[UIImageView alloc] init]; 139 | imgView.frame = CGRectMake(cX - iW / 2, cY - iH / 2, iW, iH); 140 | imgView.image = image; 141 | 142 | // 文字 143 | UILabel *label = [[UILabel alloc] init]; 144 | label.font = [UIFont systemFontOfSize:17]; 145 | label.textColor = color; 146 | label.text = message; 147 | label.textAlignment = NSTextAlignmentCenter; 148 | label.frame = CGRectMake(0, CGRectGetMaxY(imgView.frame) + 24, sW, label.font.lineHeight); 149 | 150 | // 视图 151 | XYNoDataView *view = [[XYNoDataView alloc] init]; 152 | [view addSubview:imgView]; 153 | [view addSubview:label]; 154 | 155 | // 实现跟随 TableView 滚动 156 | [view addObserver:self forKeyPath:kXYNoDataViewObserveKeyPath options:NSKeyValueObservingOptionNew context:nil]; 157 | return view; 158 | } 159 | 160 | 161 | /** 162 | 监听 163 | */ 164 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 165 | if ([keyPath isEqualToString:kXYNoDataViewObserveKeyPath]) { 166 | 167 | /** 168 | 在 TableView 滚动 ContentOffset 改变时, 会同步改变 backgroundView 的 frame.origin.y 169 | 可以实现, backgroundView 位置相对于 TableView 不动, 但是我们希望 170 | backgroundView 跟随 TableView 的滚动而滚动, 只能强制设置 frame.origin.y 永远为 0 171 | 兼容 MJRefresh 172 | */ 173 | CGRect frame = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue]; 174 | if (frame.origin.y != 0) { 175 | frame.origin.y = 0; 176 | self.backgroundView.frame = frame; 177 | } 178 | } 179 | } 180 | 181 | #pragma mark - 属性 182 | 183 | /** 184 | 设置已经加载完成数据了 185 | */ 186 | - (void)setIsInitFinish:(BOOL)finish { 187 | objc_setAssociatedObject(self, @selector(isInitFinish), @(finish), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 188 | } 189 | 190 | /** 191 | 是否已经加载完成数据 192 | */ 193 | - (BOOL)isInitFinish { 194 | id obj = objc_getAssociatedObject(self, _cmd); 195 | return [obj boolValue]; 196 | } 197 | 198 | /** 199 | 移除 KVO 监听 200 | */ 201 | - (void)freeNoDataViewIfNeeded { 202 | 203 | if ([self.backgroundView isKindOfClass:[XYNoDataView class]]) { 204 | [self.backgroundView removeObserver:self forKeyPath:kXYNoDataViewObserveKeyPath context:nil]; 205 | } 206 | } 207 | 208 | - (void)xy_dealloc { 209 | [self freeNoDataViewIfNeeded]; 210 | [self xy_dealloc]; 211 | NSLog(@"CollectionView + XY 视图正常销毁"); 212 | } 213 | 214 | @end 215 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/UITableView+XY.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XY.h 3 | // XYTableViewNoDataView 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 iCourt. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (XY) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/UITableView+XY.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XY.m 3 | // XYTableViewNoDataView 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 iCourt. All rights reserved. 7 | // 8 | 9 | #import "UITableView+XY.h" 10 | #import "XYNoDataView.h" 11 | #import 12 | 13 | /** 14 | 消除警告 15 | */ 16 | @protocol XYTableViewDelegate 17 | @optional 18 | - (UIView *)xy_noDataView; // 完全自定义占位图 19 | - (UIImage *)xy_noDataViewImage; // 使用默认占位图, 提供一张图片, 可不提供, 默认不显示 20 | - (NSString *)xy_noDataViewMessage; // 使用默认占位图, 提供显示文字, 可不提供, 默认为暂无数据 21 | - (UIColor *)xy_noDataViewMessageColor; // 使用默认占位图, 提供显示文字颜色, 可不提供, 默认为灰色 22 | - (NSNumber *)xy_noDataViewCenterYOffset; // 使用默认占位图, CenterY 向下的偏移量 23 | @end 24 | 25 | 26 | @implementation UITableView (XY) 27 | 28 | 29 | /** 30 | 加载时, 交换方法 31 | */ 32 | + (void)load { 33 | 34 | // 只交换一次 35 | static dispatch_once_t onceToken; 36 | dispatch_once(&onceToken, ^{ 37 | 38 | Method reloadData = class_getInstanceMethod(self, @selector(reloadData)); 39 | Method xy_reloadData = class_getInstanceMethod(self, @selector(xy_reloadData)); 40 | method_exchangeImplementations(reloadData, xy_reloadData); 41 | 42 | Method dealloc = class_getInstanceMethod(self, NSSelectorFromString(@"dealloc")); 43 | Method xy_dealloc = class_getInstanceMethod(self, @selector(xy_dealloc)); 44 | method_exchangeImplementations(dealloc, xy_dealloc); 45 | }); 46 | } 47 | 48 | /** 49 | 在 ReloadData 的时候检查数据 50 | */ 51 | - (void)xy_reloadData { 52 | 53 | [self xy_reloadData]; 54 | 55 | // 忽略第一次加载 56 | if (![self isInitFinish]) { 57 | [self xy_havingData:YES]; 58 | [self setIsInitFinish:YES]; 59 | return ; 60 | } 61 | // 刷新完成之后检测数据量 62 | dispatch_async(dispatch_get_main_queue(), ^{ 63 | 64 | NSInteger numberOfSections = [self numberOfSections]; 65 | BOOL havingData = NO; 66 | for (NSInteger i = 0; i < numberOfSections; i++) { 67 | if ([self numberOfRowsInSection:i] > 0) { 68 | havingData = YES; 69 | break; 70 | } 71 | } 72 | 73 | [self xy_havingData:havingData]; 74 | }); 75 | } 76 | 77 | /** 78 | 展示占位图 79 | */ 80 | - (void)xy_havingData:(BOOL)havingData { 81 | 82 | // 不需要显示占位图 83 | if (havingData) { 84 | [self freeNoDataViewIfNeeded]; 85 | self.backgroundView = nil; 86 | return ; 87 | } 88 | 89 | // 不需要重复创建 90 | if (self.backgroundView) { 91 | return ; 92 | } 93 | 94 | // 自定义了占位图 95 | if ([self.delegate respondsToSelector:@selector(xy_noDataView)]) { 96 | self.backgroundView = [self.delegate performSelector:@selector(xy_noDataView)]; 97 | return ; 98 | } 99 | 100 | // 使用自带的 101 | UIImage *img = nil; 102 | NSString *msg = @"暂无数据"; 103 | UIColor *color = [UIColor lightGrayColor]; 104 | CGFloat offset = 0; 105 | 106 | // 获取图片 107 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewImage)]) { 108 | img = [self.delegate performSelector:@selector(xy_noDataViewImage)]; 109 | } 110 | // 获取文字 111 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewMessage)]) { 112 | msg = [self.delegate performSelector:@selector(xy_noDataViewMessage)]; 113 | } 114 | // 获取颜色 115 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewMessageColor)]) { 116 | color = [self.delegate performSelector:@selector(xy_noDataViewMessageColor)]; 117 | } 118 | // 获取偏移量 119 | if ([self.delegate respondsToSelector:@selector(xy_noDataViewCenterYOffset)]) { 120 | offset = [[self.delegate performSelector:@selector(xy_noDataViewCenterYOffset)] floatValue]; 121 | } 122 | 123 | // 创建占位图 124 | self.backgroundView = [self xy_defaultNoDataViewWithImage :img message:msg color:color offsetY:offset]; 125 | } 126 | 127 | /** 128 | 默认的占位图 129 | */ 130 | - (UIView *)xy_defaultNoDataViewWithImage:(UIImage *)image message:(NSString *)message color:(UIColor *)color offsetY:(CGFloat)offset { 131 | 132 | // 计算位置, 垂直居中, 图片默认中心偏上. 133 | CGFloat sW = self.bounds.size.width; 134 | CGFloat cX = sW / 2; 135 | CGFloat cY = self.bounds.size.height * (1 - 0.618) + offset; 136 | CGFloat iW = image.size.width; 137 | CGFloat iH = image.size.height; 138 | 139 | // 图片 140 | UIImageView *imgView = [[UIImageView alloc] init]; 141 | imgView.frame = CGRectMake(cX - iW / 2, cY - iH / 2, iW, iH); 142 | imgView.image = image; 143 | 144 | // 文字 145 | UILabel *label = [[UILabel alloc] init]; 146 | label.font = [UIFont systemFontOfSize:17]; 147 | label.textColor = color; 148 | label.text = message; 149 | label.textAlignment = NSTextAlignmentCenter; 150 | label.frame = CGRectMake(0, CGRectGetMaxY(imgView.frame) + 24, sW, label.font.lineHeight); 151 | 152 | // 视图 153 | XYNoDataView *view = [[XYNoDataView alloc] init]; 154 | [view addSubview:imgView]; 155 | [view addSubview:label]; 156 | 157 | // 实现跟随 TableView 滚动 158 | [view addObserver:self forKeyPath:kXYNoDataViewObserveKeyPath options:NSKeyValueObservingOptionNew context:nil]; 159 | return view; 160 | } 161 | 162 | 163 | /** 164 | 监听 165 | */ 166 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 167 | if ([keyPath isEqualToString:kXYNoDataViewObserveKeyPath]) { 168 | 169 | /** 170 | 在 TableView 滚动 ContentOffset 改变时, 会同步改变 backgroundView 的 frame.origin.y 171 | 可以实现, backgroundView 位置相对于 TableView 不动, 但是我们希望 172 | backgroundView 跟随 TableView 的滚动而滚动, 只能强制设置 frame.origin.y 永远为 0 173 | 兼容 MJRefresh 174 | */ 175 | CGRect frame = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue]; 176 | if (frame.origin.y != 0) { 177 | frame.origin.y = 0; 178 | self.backgroundView.frame = frame; 179 | } 180 | } 181 | } 182 | 183 | #pragma mark - 属性 184 | 185 | /** 186 | 设置已经加载完成数据了 187 | */ 188 | - (void)setIsInitFinish:(BOOL)finish { 189 | objc_setAssociatedObject(self, @selector(isInitFinish), @(finish), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 190 | } 191 | 192 | /** 193 | 是否已经加载完成数据 194 | */ 195 | - (BOOL)isInitFinish { 196 | id obj = objc_getAssociatedObject(self, _cmd); 197 | return [obj boolValue]; 198 | } 199 | 200 | /** 201 | 移除 KVO 监听 202 | */ 203 | - (void)freeNoDataViewIfNeeded { 204 | 205 | if ([self.backgroundView isKindOfClass:[XYNoDataView class]]) { 206 | [self.backgroundView removeObserver:self forKeyPath:kXYNoDataViewObserveKeyPath context:nil]; 207 | } 208 | } 209 | 210 | - (void)xy_dealloc { 211 | [self freeNoDataViewIfNeeded]; 212 | [self xy_dealloc]; 213 | NSLog(@"TableView + XY 视图正常销毁"); 214 | } 215 | 216 | @end 217 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/XYNoDataView.h: -------------------------------------------------------------------------------- 1 | // 2 | // XYNoDataView.h 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/11/3. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString * const kXYNoDataViewObserveKeyPath; 12 | 13 | @interface XYNoDataView : UIView 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataView/XYNoDataView.m: -------------------------------------------------------------------------------- 1 | // 2 | // XYNoDataView.m 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/11/3. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import "XYNoDataView.h" 10 | 11 | NSString * const kXYNoDataViewObserveKeyPath = @"frame"; 12 | 13 | @implementation XYNoDataView 14 | 15 | - (void)dealloc { 16 | NSLog(@"占位视图正常销毁"); 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 915E9C951FAC70350012BFF2 /* XYNoDataView.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9C941FAC70350012BFF2 /* XYNoDataView.m */; }; 11 | 915E9CC51FAC74240012BFF2 /* UIScrollView+MJRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9C971FAC74240012BFF2 /* UIScrollView+MJRefresh.m */; }; 12 | 915E9CC61FAC74240012BFF2 /* MJRefreshConst.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9C981FAC74240012BFF2 /* MJRefreshConst.m */; }; 13 | 915E9CC71FAC74240012BFF2 /* MJRefresh.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 915E9C9C1FAC74240012BFF2 /* MJRefresh.bundle */; }; 14 | 915E9CC81FAC74240012BFF2 /* UIScrollView+MJExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9C9E1FAC74240012BFF2 /* UIScrollView+MJExtension.m */; }; 15 | 915E9CC91FAC74240012BFF2 /* NSBundle+MJRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CA11FAC74240012BFF2 /* NSBundle+MJRefresh.m */; }; 16 | 915E9CCA1FAC74240012BFF2 /* UIView+MJExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CA21FAC74240012BFF2 /* UIView+MJExtension.m */; }; 17 | 915E9CCB1FAC74240012BFF2 /* MJRefreshBackGifFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CA91FAC74240012BFF2 /* MJRefreshBackGifFooter.m */; }; 18 | 915E9CCC1FAC74240012BFF2 /* MJRefreshBackStateFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CAA1FAC74240012BFF2 /* MJRefreshBackStateFooter.m */; }; 19 | 915E9CCD1FAC74240012BFF2 /* MJRefreshBackNormalFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CAB1FAC74240012BFF2 /* MJRefreshBackNormalFooter.m */; }; 20 | 915E9CCE1FAC74240012BFF2 /* MJRefreshAutoStateFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB01FAC74240012BFF2 /* MJRefreshAutoStateFooter.m */; }; 21 | 915E9CCF1FAC74240012BFF2 /* MJRefreshAutoGifFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB11FAC74240012BFF2 /* MJRefreshAutoGifFooter.m */; }; 22 | 915E9CD01FAC74240012BFF2 /* MJRefreshAutoNormalFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB21FAC74240012BFF2 /* MJRefreshAutoNormalFooter.m */; }; 23 | 915E9CD11FAC74240012BFF2 /* MJRefreshNormalHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB41FAC74240012BFF2 /* MJRefreshNormalHeader.m */; }; 24 | 915E9CD21FAC74240012BFF2 /* MJRefreshStateHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB81FAC74240012BFF2 /* MJRefreshStateHeader.m */; }; 25 | 915E9CD31FAC74240012BFF2 /* MJRefreshGifHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CB91FAC74240012BFF2 /* MJRefreshGifHeader.m */; }; 26 | 915E9CD41FAC74240012BFF2 /* MJRefreshFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CBB1FAC74240012BFF2 /* MJRefreshFooter.m */; }; 27 | 915E9CD51FAC74240012BFF2 /* MJRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CBD1FAC74240012BFF2 /* MJRefreshHeader.m */; }; 28 | 915E9CD61FAC74240012BFF2 /* MJRefreshBackFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CBF1FAC74240012BFF2 /* MJRefreshBackFooter.m */; }; 29 | 915E9CD71FAC74240012BFF2 /* MJRefreshAutoFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CC01FAC74240012BFF2 /* MJRefreshAutoFooter.m */; }; 30 | 915E9CD81FAC74240012BFF2 /* MJRefreshComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 915E9CC21FAC74240012BFF2 /* MJRefreshComponent.m */; }; 31 | 918E784F1F1F4EE000298F79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 918E784E1F1F4EE000298F79 /* main.m */; }; 32 | 918E78521F1F4EE000298F79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 918E78511F1F4EE000298F79 /* AppDelegate.m */; }; 33 | 918E78551F1F4EE000298F79 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 918E78541F1F4EE000298F79 /* ViewController.m */; }; 34 | 918E78581F1F4EE000298F79 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 918E78561F1F4EE000298F79 /* Main.storyboard */; }; 35 | 918E785A1F1F4EE000298F79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 918E78591F1F4EE000298F79 /* Assets.xcassets */; }; 36 | 918E785D1F1F4EE000298F79 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 918E785B1F1F4EE000298F79 /* LaunchScreen.storyboard */; }; 37 | 918E786B1F1F4FDD00298F79 /* UICollectionView+XY.m in Sources */ = {isa = PBXBuildFile; fileRef = 918E78681F1F4FDD00298F79 /* UICollectionView+XY.m */; }; 38 | 918E786C1F1F4FDD00298F79 /* UITableView+XY.m in Sources */ = {isa = PBXBuildFile; fileRef = 918E786A1F1F4FDD00298F79 /* UITableView+XY.m */; }; 39 | /* End PBXBuildFile section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 915E9C931FAC70350012BFF2 /* XYNoDataView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XYNoDataView.h; sourceTree = ""; }; 43 | 915E9C941FAC70350012BFF2 /* XYNoDataView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XYNoDataView.m; sourceTree = ""; }; 44 | 915E9C971FAC74240012BFF2 /* UIScrollView+MJRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+MJRefresh.m"; sourceTree = ""; }; 45 | 915E9C981FAC74240012BFF2 /* MJRefreshConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshConst.m; sourceTree = ""; }; 46 | 915E9C991FAC74240012BFF2 /* UIScrollView+MJExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+MJExtension.h"; sourceTree = ""; }; 47 | 915E9C9A1FAC74240012BFF2 /* MJRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefresh.h; sourceTree = ""; }; 48 | 915E9C9B1FAC74240012BFF2 /* NSBundle+MJRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+MJRefresh.h"; sourceTree = ""; }; 49 | 915E9C9C1FAC74240012BFF2 /* MJRefresh.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = MJRefresh.bundle; sourceTree = ""; }; 50 | 915E9C9D1FAC74240012BFF2 /* UIView+MJExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MJExtension.h"; sourceTree = ""; }; 51 | 915E9C9E1FAC74240012BFF2 /* UIScrollView+MJExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+MJExtension.m"; sourceTree = ""; }; 52 | 915E9C9F1FAC74240012BFF2 /* MJRefreshConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshConst.h; sourceTree = ""; }; 53 | 915E9CA01FAC74240012BFF2 /* UIScrollView+MJRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+MJRefresh.h"; sourceTree = ""; }; 54 | 915E9CA11FAC74240012BFF2 /* NSBundle+MJRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+MJRefresh.m"; sourceTree = ""; }; 55 | 915E9CA21FAC74240012BFF2 /* UIView+MJExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MJExtension.m"; sourceTree = ""; }; 56 | 915E9CA61FAC74240012BFF2 /* MJRefreshBackGifFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshBackGifFooter.h; sourceTree = ""; }; 57 | 915E9CA71FAC74240012BFF2 /* MJRefreshBackStateFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshBackStateFooter.h; sourceTree = ""; }; 58 | 915E9CA81FAC74240012BFF2 /* MJRefreshBackNormalFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshBackNormalFooter.h; sourceTree = ""; }; 59 | 915E9CA91FAC74240012BFF2 /* MJRefreshBackGifFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshBackGifFooter.m; sourceTree = ""; }; 60 | 915E9CAA1FAC74240012BFF2 /* MJRefreshBackStateFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshBackStateFooter.m; sourceTree = ""; }; 61 | 915E9CAB1FAC74240012BFF2 /* MJRefreshBackNormalFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshBackNormalFooter.m; sourceTree = ""; }; 62 | 915E9CAD1FAC74240012BFF2 /* MJRefreshAutoStateFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshAutoStateFooter.h; sourceTree = ""; }; 63 | 915E9CAE1FAC74240012BFF2 /* MJRefreshAutoNormalFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshAutoNormalFooter.h; sourceTree = ""; }; 64 | 915E9CAF1FAC74240012BFF2 /* MJRefreshAutoGifFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshAutoGifFooter.h; sourceTree = ""; }; 65 | 915E9CB01FAC74240012BFF2 /* MJRefreshAutoStateFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshAutoStateFooter.m; sourceTree = ""; }; 66 | 915E9CB11FAC74240012BFF2 /* MJRefreshAutoGifFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshAutoGifFooter.m; sourceTree = ""; }; 67 | 915E9CB21FAC74240012BFF2 /* MJRefreshAutoNormalFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshAutoNormalFooter.m; sourceTree = ""; }; 68 | 915E9CB41FAC74240012BFF2 /* MJRefreshNormalHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshNormalHeader.m; sourceTree = ""; }; 69 | 915E9CB51FAC74240012BFF2 /* MJRefreshStateHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshStateHeader.h; sourceTree = ""; }; 70 | 915E9CB61FAC74240012BFF2 /* MJRefreshGifHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshGifHeader.h; sourceTree = ""; }; 71 | 915E9CB71FAC74240012BFF2 /* MJRefreshNormalHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshNormalHeader.h; sourceTree = ""; }; 72 | 915E9CB81FAC74240012BFF2 /* MJRefreshStateHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshStateHeader.m; sourceTree = ""; }; 73 | 915E9CB91FAC74240012BFF2 /* MJRefreshGifHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshGifHeader.m; sourceTree = ""; }; 74 | 915E9CBB1FAC74240012BFF2 /* MJRefreshFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshFooter.m; sourceTree = ""; }; 75 | 915E9CBC1FAC74240012BFF2 /* MJRefreshComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshComponent.h; sourceTree = ""; }; 76 | 915E9CBD1FAC74240012BFF2 /* MJRefreshHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshHeader.m; sourceTree = ""; }; 77 | 915E9CBE1FAC74240012BFF2 /* MJRefreshAutoFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshAutoFooter.h; sourceTree = ""; }; 78 | 915E9CBF1FAC74240012BFF2 /* MJRefreshBackFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshBackFooter.m; sourceTree = ""; }; 79 | 915E9CC01FAC74240012BFF2 /* MJRefreshAutoFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshAutoFooter.m; sourceTree = ""; }; 80 | 915E9CC11FAC74240012BFF2 /* MJRefreshHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshHeader.h; sourceTree = ""; }; 81 | 915E9CC21FAC74240012BFF2 /* MJRefreshComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshComponent.m; sourceTree = ""; }; 82 | 915E9CC31FAC74240012BFF2 /* MJRefreshFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshFooter.h; sourceTree = ""; }; 83 | 915E9CC41FAC74240012BFF2 /* MJRefreshBackFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshBackFooter.h; sourceTree = ""; }; 84 | 918E784A1F1F4EE000298F79 /* XYTableViewNoDataViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XYTableViewNoDataViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 85 | 918E784E1F1F4EE000298F79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 86 | 918E78501F1F4EE000298F79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 87 | 918E78511F1F4EE000298F79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 88 | 918E78531F1F4EE000298F79 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 89 | 918E78541F1F4EE000298F79 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 90 | 918E78571F1F4EE000298F79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 91 | 918E78591F1F4EE000298F79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 92 | 918E785C1F1F4EE000298F79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 93 | 918E785E1F1F4EE100298F79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 94 | 918E78641F1F4EF100298F79 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 95 | 918E78671F1F4FDD00298F79 /* UICollectionView+XY.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UICollectionView+XY.h"; sourceTree = ""; }; 96 | 918E78681F1F4FDD00298F79 /* UICollectionView+XY.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UICollectionView+XY.m"; sourceTree = ""; }; 97 | 918E78691F1F4FDD00298F79 /* UITableView+XY.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableView+XY.h"; sourceTree = ""; }; 98 | 918E786A1F1F4FDD00298F79 /* UITableView+XY.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableView+XY.m"; sourceTree = ""; }; 99 | /* End PBXFileReference section */ 100 | 101 | /* Begin PBXFrameworksBuildPhase section */ 102 | 918E78471F1F4EE000298F79 /* Frameworks */ = { 103 | isa = PBXFrameworksBuildPhase; 104 | buildActionMask = 2147483647; 105 | files = ( 106 | ); 107 | runOnlyForDeploymentPostprocessing = 0; 108 | }; 109 | /* End PBXFrameworksBuildPhase section */ 110 | 111 | /* Begin PBXGroup section */ 112 | 915E9C961FAC74240012BFF2 /* MJRefresh */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 915E9C971FAC74240012BFF2 /* UIScrollView+MJRefresh.m */, 116 | 915E9C981FAC74240012BFF2 /* MJRefreshConst.m */, 117 | 915E9C991FAC74240012BFF2 /* UIScrollView+MJExtension.h */, 118 | 915E9C9A1FAC74240012BFF2 /* MJRefresh.h */, 119 | 915E9C9B1FAC74240012BFF2 /* NSBundle+MJRefresh.h */, 120 | 915E9C9C1FAC74240012BFF2 /* MJRefresh.bundle */, 121 | 915E9C9D1FAC74240012BFF2 /* UIView+MJExtension.h */, 122 | 915E9C9E1FAC74240012BFF2 /* UIScrollView+MJExtension.m */, 123 | 915E9C9F1FAC74240012BFF2 /* MJRefreshConst.h */, 124 | 915E9CA01FAC74240012BFF2 /* UIScrollView+MJRefresh.h */, 125 | 915E9CA11FAC74240012BFF2 /* NSBundle+MJRefresh.m */, 126 | 915E9CA21FAC74240012BFF2 /* UIView+MJExtension.m */, 127 | 915E9CA31FAC74240012BFF2 /* Custom */, 128 | 915E9CBA1FAC74240012BFF2 /* Base */, 129 | ); 130 | path = MJRefresh; 131 | sourceTree = ""; 132 | }; 133 | 915E9CA31FAC74240012BFF2 /* Custom */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 915E9CA41FAC74240012BFF2 /* Footer */, 137 | 915E9CB31FAC74240012BFF2 /* Header */, 138 | ); 139 | path = Custom; 140 | sourceTree = ""; 141 | }; 142 | 915E9CA41FAC74240012BFF2 /* Footer */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 915E9CA51FAC74240012BFF2 /* Back */, 146 | 915E9CAC1FAC74240012BFF2 /* Auto */, 147 | ); 148 | path = Footer; 149 | sourceTree = ""; 150 | }; 151 | 915E9CA51FAC74240012BFF2 /* Back */ = { 152 | isa = PBXGroup; 153 | children = ( 154 | 915E9CA61FAC74240012BFF2 /* MJRefreshBackGifFooter.h */, 155 | 915E9CA71FAC74240012BFF2 /* MJRefreshBackStateFooter.h */, 156 | 915E9CA81FAC74240012BFF2 /* MJRefreshBackNormalFooter.h */, 157 | 915E9CA91FAC74240012BFF2 /* MJRefreshBackGifFooter.m */, 158 | 915E9CAA1FAC74240012BFF2 /* MJRefreshBackStateFooter.m */, 159 | 915E9CAB1FAC74240012BFF2 /* MJRefreshBackNormalFooter.m */, 160 | ); 161 | path = Back; 162 | sourceTree = ""; 163 | }; 164 | 915E9CAC1FAC74240012BFF2 /* Auto */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 915E9CAD1FAC74240012BFF2 /* MJRefreshAutoStateFooter.h */, 168 | 915E9CAE1FAC74240012BFF2 /* MJRefreshAutoNormalFooter.h */, 169 | 915E9CAF1FAC74240012BFF2 /* MJRefreshAutoGifFooter.h */, 170 | 915E9CB01FAC74240012BFF2 /* MJRefreshAutoStateFooter.m */, 171 | 915E9CB11FAC74240012BFF2 /* MJRefreshAutoGifFooter.m */, 172 | 915E9CB21FAC74240012BFF2 /* MJRefreshAutoNormalFooter.m */, 173 | ); 174 | path = Auto; 175 | sourceTree = ""; 176 | }; 177 | 915E9CB31FAC74240012BFF2 /* Header */ = { 178 | isa = PBXGroup; 179 | children = ( 180 | 915E9CB41FAC74240012BFF2 /* MJRefreshNormalHeader.m */, 181 | 915E9CB51FAC74240012BFF2 /* MJRefreshStateHeader.h */, 182 | 915E9CB61FAC74240012BFF2 /* MJRefreshGifHeader.h */, 183 | 915E9CB71FAC74240012BFF2 /* MJRefreshNormalHeader.h */, 184 | 915E9CB81FAC74240012BFF2 /* MJRefreshStateHeader.m */, 185 | 915E9CB91FAC74240012BFF2 /* MJRefreshGifHeader.m */, 186 | ); 187 | path = Header; 188 | sourceTree = ""; 189 | }; 190 | 915E9CBA1FAC74240012BFF2 /* Base */ = { 191 | isa = PBXGroup; 192 | children = ( 193 | 915E9CBB1FAC74240012BFF2 /* MJRefreshFooter.m */, 194 | 915E9CBC1FAC74240012BFF2 /* MJRefreshComponent.h */, 195 | 915E9CBD1FAC74240012BFF2 /* MJRefreshHeader.m */, 196 | 915E9CBE1FAC74240012BFF2 /* MJRefreshAutoFooter.h */, 197 | 915E9CBF1FAC74240012BFF2 /* MJRefreshBackFooter.m */, 198 | 915E9CC01FAC74240012BFF2 /* MJRefreshAutoFooter.m */, 199 | 915E9CC11FAC74240012BFF2 /* MJRefreshHeader.h */, 200 | 915E9CC21FAC74240012BFF2 /* MJRefreshComponent.m */, 201 | 915E9CC31FAC74240012BFF2 /* MJRefreshFooter.h */, 202 | 915E9CC41FAC74240012BFF2 /* MJRefreshBackFooter.h */, 203 | ); 204 | path = Base; 205 | sourceTree = ""; 206 | }; 207 | 918E78411F1F4EE000298F79 = { 208 | isa = PBXGroup; 209 | children = ( 210 | 918E78661F1F4FDD00298F79 /* XYTableViewNoDataView */, 211 | 918E784C1F1F4EE000298F79 /* XYTableViewNoDataViewDemo */, 212 | 918E784B1F1F4EE000298F79 /* Products */, 213 | 918E78641F1F4EF100298F79 /* README.md */, 214 | ); 215 | sourceTree = ""; 216 | }; 217 | 918E784B1F1F4EE000298F79 /* Products */ = { 218 | isa = PBXGroup; 219 | children = ( 220 | 918E784A1F1F4EE000298F79 /* XYTableViewNoDataViewDemo.app */, 221 | ); 222 | name = Products; 223 | sourceTree = ""; 224 | }; 225 | 918E784C1F1F4EE000298F79 /* XYTableViewNoDataViewDemo */ = { 226 | isa = PBXGroup; 227 | children = ( 228 | 915E9C961FAC74240012BFF2 /* MJRefresh */, 229 | 918E78501F1F4EE000298F79 /* AppDelegate.h */, 230 | 918E78511F1F4EE000298F79 /* AppDelegate.m */, 231 | 918E78531F1F4EE000298F79 /* ViewController.h */, 232 | 918E78541F1F4EE000298F79 /* ViewController.m */, 233 | 918E78561F1F4EE000298F79 /* Main.storyboard */, 234 | 918E78591F1F4EE000298F79 /* Assets.xcassets */, 235 | 918E785B1F1F4EE000298F79 /* LaunchScreen.storyboard */, 236 | 918E785E1F1F4EE100298F79 /* Info.plist */, 237 | 918E784D1F1F4EE000298F79 /* Supporting Files */, 238 | ); 239 | path = XYTableViewNoDataViewDemo; 240 | sourceTree = ""; 241 | }; 242 | 918E784D1F1F4EE000298F79 /* Supporting Files */ = { 243 | isa = PBXGroup; 244 | children = ( 245 | 918E784E1F1F4EE000298F79 /* main.m */, 246 | ); 247 | name = "Supporting Files"; 248 | sourceTree = ""; 249 | }; 250 | 918E78661F1F4FDD00298F79 /* XYTableViewNoDataView */ = { 251 | isa = PBXGroup; 252 | children = ( 253 | 918E78671F1F4FDD00298F79 /* UICollectionView+XY.h */, 254 | 918E78681F1F4FDD00298F79 /* UICollectionView+XY.m */, 255 | 918E78691F1F4FDD00298F79 /* UITableView+XY.h */, 256 | 918E786A1F1F4FDD00298F79 /* UITableView+XY.m */, 257 | 915E9C931FAC70350012BFF2 /* XYNoDataView.h */, 258 | 915E9C941FAC70350012BFF2 /* XYNoDataView.m */, 259 | ); 260 | path = XYTableViewNoDataView; 261 | sourceTree = ""; 262 | }; 263 | /* End PBXGroup section */ 264 | 265 | /* Begin PBXNativeTarget section */ 266 | 918E78491F1F4EE000298F79 /* XYTableViewNoDataViewDemo */ = { 267 | isa = PBXNativeTarget; 268 | buildConfigurationList = 918E78611F1F4EE100298F79 /* Build configuration list for PBXNativeTarget "XYTableViewNoDataViewDemo" */; 269 | buildPhases = ( 270 | 918E78461F1F4EE000298F79 /* Sources */, 271 | 918E78471F1F4EE000298F79 /* Frameworks */, 272 | 918E78481F1F4EE000298F79 /* Resources */, 273 | ); 274 | buildRules = ( 275 | ); 276 | dependencies = ( 277 | ); 278 | name = XYTableViewNoDataViewDemo; 279 | productName = XYTableViewNoDataViewDemo; 280 | productReference = 918E784A1F1F4EE000298F79 /* XYTableViewNoDataViewDemo.app */; 281 | productType = "com.apple.product-type.application"; 282 | }; 283 | /* End PBXNativeTarget section */ 284 | 285 | /* Begin PBXProject section */ 286 | 918E78421F1F4EE000298F79 /* Project object */ = { 287 | isa = PBXProject; 288 | attributes = { 289 | LastUpgradeCheck = 0910; 290 | ORGANIZATIONNAME = "韩元旭"; 291 | TargetAttributes = { 292 | 918E78491F1F4EE000298F79 = { 293 | CreatedOnToolsVersion = 8.3.3; 294 | DevelopmentTeam = 9H2RBN3WMR; 295 | ProvisioningStyle = Automatic; 296 | }; 297 | }; 298 | }; 299 | buildConfigurationList = 918E78451F1F4EE000298F79 /* Build configuration list for PBXProject "XYTableViewNoDataViewDemo" */; 300 | compatibilityVersion = "Xcode 3.2"; 301 | developmentRegion = English; 302 | hasScannedForEncodings = 0; 303 | knownRegions = ( 304 | en, 305 | Base, 306 | ); 307 | mainGroup = 918E78411F1F4EE000298F79; 308 | productRefGroup = 918E784B1F1F4EE000298F79 /* Products */; 309 | projectDirPath = ""; 310 | projectRoot = ""; 311 | targets = ( 312 | 918E78491F1F4EE000298F79 /* XYTableViewNoDataViewDemo */, 313 | ); 314 | }; 315 | /* End PBXProject section */ 316 | 317 | /* Begin PBXResourcesBuildPhase section */ 318 | 918E78481F1F4EE000298F79 /* Resources */ = { 319 | isa = PBXResourcesBuildPhase; 320 | buildActionMask = 2147483647; 321 | files = ( 322 | 918E785D1F1F4EE000298F79 /* LaunchScreen.storyboard in Resources */, 323 | 918E785A1F1F4EE000298F79 /* Assets.xcassets in Resources */, 324 | 915E9CC71FAC74240012BFF2 /* MJRefresh.bundle in Resources */, 325 | 918E78581F1F4EE000298F79 /* Main.storyboard in Resources */, 326 | ); 327 | runOnlyForDeploymentPostprocessing = 0; 328 | }; 329 | /* End PBXResourcesBuildPhase section */ 330 | 331 | /* Begin PBXSourcesBuildPhase section */ 332 | 918E78461F1F4EE000298F79 /* Sources */ = { 333 | isa = PBXSourcesBuildPhase; 334 | buildActionMask = 2147483647; 335 | files = ( 336 | 915E9CD11FAC74240012BFF2 /* MJRefreshNormalHeader.m in Sources */, 337 | 915E9CD21FAC74240012BFF2 /* MJRefreshStateHeader.m in Sources */, 338 | 915E9CC81FAC74240012BFF2 /* UIScrollView+MJExtension.m in Sources */, 339 | 915E9CCD1FAC74240012BFF2 /* MJRefreshBackNormalFooter.m in Sources */, 340 | 915E9CCE1FAC74240012BFF2 /* MJRefreshAutoStateFooter.m in Sources */, 341 | 915E9CC61FAC74240012BFF2 /* MJRefreshConst.m in Sources */, 342 | 915E9CCC1FAC74240012BFF2 /* MJRefreshBackStateFooter.m in Sources */, 343 | 918E786C1F1F4FDD00298F79 /* UITableView+XY.m in Sources */, 344 | 915E9CD31FAC74240012BFF2 /* MJRefreshGifHeader.m in Sources */, 345 | 915E9CD01FAC74240012BFF2 /* MJRefreshAutoNormalFooter.m in Sources */, 346 | 915E9CC91FAC74240012BFF2 /* NSBundle+MJRefresh.m in Sources */, 347 | 915E9CCF1FAC74240012BFF2 /* MJRefreshAutoGifFooter.m in Sources */, 348 | 915E9CD81FAC74240012BFF2 /* MJRefreshComponent.m in Sources */, 349 | 915E9CD61FAC74240012BFF2 /* MJRefreshBackFooter.m in Sources */, 350 | 918E786B1F1F4FDD00298F79 /* UICollectionView+XY.m in Sources */, 351 | 918E78551F1F4EE000298F79 /* ViewController.m in Sources */, 352 | 918E78521F1F4EE000298F79 /* AppDelegate.m in Sources */, 353 | 915E9CCB1FAC74240012BFF2 /* MJRefreshBackGifFooter.m in Sources */, 354 | 915E9CC51FAC74240012BFF2 /* UIScrollView+MJRefresh.m in Sources */, 355 | 918E784F1F1F4EE000298F79 /* main.m in Sources */, 356 | 915E9CCA1FAC74240012BFF2 /* UIView+MJExtension.m in Sources */, 357 | 915E9C951FAC70350012BFF2 /* XYNoDataView.m in Sources */, 358 | 915E9CD41FAC74240012BFF2 /* MJRefreshFooter.m in Sources */, 359 | 915E9CD71FAC74240012BFF2 /* MJRefreshAutoFooter.m in Sources */, 360 | 915E9CD51FAC74240012BFF2 /* MJRefreshHeader.m in Sources */, 361 | ); 362 | runOnlyForDeploymentPostprocessing = 0; 363 | }; 364 | /* End PBXSourcesBuildPhase section */ 365 | 366 | /* Begin PBXVariantGroup section */ 367 | 918E78561F1F4EE000298F79 /* Main.storyboard */ = { 368 | isa = PBXVariantGroup; 369 | children = ( 370 | 918E78571F1F4EE000298F79 /* Base */, 371 | ); 372 | name = Main.storyboard; 373 | sourceTree = ""; 374 | }; 375 | 918E785B1F1F4EE000298F79 /* LaunchScreen.storyboard */ = { 376 | isa = PBXVariantGroup; 377 | children = ( 378 | 918E785C1F1F4EE000298F79 /* Base */, 379 | ); 380 | name = LaunchScreen.storyboard; 381 | sourceTree = ""; 382 | }; 383 | /* End PBXVariantGroup section */ 384 | 385 | /* Begin XCBuildConfiguration section */ 386 | 918E785F1F1F4EE100298F79 /* Debug */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | ALWAYS_SEARCH_USER_PATHS = NO; 390 | CLANG_ANALYZER_NONNULL = YES; 391 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 392 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 393 | CLANG_CXX_LIBRARY = "libc++"; 394 | CLANG_ENABLE_MODULES = YES; 395 | CLANG_ENABLE_OBJC_ARC = YES; 396 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 397 | CLANG_WARN_BOOL_CONVERSION = YES; 398 | CLANG_WARN_COMMA = YES; 399 | CLANG_WARN_CONSTANT_CONVERSION = YES; 400 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 401 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 402 | CLANG_WARN_EMPTY_BODY = YES; 403 | CLANG_WARN_ENUM_CONVERSION = YES; 404 | CLANG_WARN_INFINITE_RECURSION = YES; 405 | CLANG_WARN_INT_CONVERSION = YES; 406 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 407 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 408 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 409 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 410 | CLANG_WARN_STRICT_PROTOTYPES = YES; 411 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 412 | CLANG_WARN_UNREACHABLE_CODE = YES; 413 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 414 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 415 | COPY_PHASE_STRIP = NO; 416 | DEBUG_INFORMATION_FORMAT = dwarf; 417 | ENABLE_STRICT_OBJC_MSGSEND = YES; 418 | ENABLE_TESTABILITY = YES; 419 | GCC_C_LANGUAGE_STANDARD = gnu99; 420 | GCC_DYNAMIC_NO_PIC = NO; 421 | GCC_NO_COMMON_BLOCKS = YES; 422 | GCC_OPTIMIZATION_LEVEL = 0; 423 | GCC_PREPROCESSOR_DEFINITIONS = ( 424 | "DEBUG=1", 425 | "$(inherited)", 426 | ); 427 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 428 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 429 | GCC_WARN_UNDECLARED_SELECTOR = YES; 430 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 431 | GCC_WARN_UNUSED_FUNCTION = YES; 432 | GCC_WARN_UNUSED_VARIABLE = YES; 433 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 434 | MTL_ENABLE_DEBUG_INFO = YES; 435 | ONLY_ACTIVE_ARCH = YES; 436 | SDKROOT = iphoneos; 437 | }; 438 | name = Debug; 439 | }; 440 | 918E78601F1F4EE100298F79 /* Release */ = { 441 | isa = XCBuildConfiguration; 442 | buildSettings = { 443 | ALWAYS_SEARCH_USER_PATHS = NO; 444 | CLANG_ANALYZER_NONNULL = YES; 445 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 446 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 447 | CLANG_CXX_LIBRARY = "libc++"; 448 | CLANG_ENABLE_MODULES = YES; 449 | CLANG_ENABLE_OBJC_ARC = YES; 450 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 451 | CLANG_WARN_BOOL_CONVERSION = YES; 452 | CLANG_WARN_COMMA = YES; 453 | CLANG_WARN_CONSTANT_CONVERSION = YES; 454 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 455 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 456 | CLANG_WARN_EMPTY_BODY = YES; 457 | CLANG_WARN_ENUM_CONVERSION = YES; 458 | CLANG_WARN_INFINITE_RECURSION = YES; 459 | CLANG_WARN_INT_CONVERSION = YES; 460 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 461 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 462 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 463 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 464 | CLANG_WARN_STRICT_PROTOTYPES = YES; 465 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 466 | CLANG_WARN_UNREACHABLE_CODE = YES; 467 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 468 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 469 | COPY_PHASE_STRIP = NO; 470 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 471 | ENABLE_NS_ASSERTIONS = NO; 472 | ENABLE_STRICT_OBJC_MSGSEND = YES; 473 | GCC_C_LANGUAGE_STANDARD = gnu99; 474 | GCC_NO_COMMON_BLOCKS = YES; 475 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 476 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 477 | GCC_WARN_UNDECLARED_SELECTOR = YES; 478 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 479 | GCC_WARN_UNUSED_FUNCTION = YES; 480 | GCC_WARN_UNUSED_VARIABLE = YES; 481 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 482 | MTL_ENABLE_DEBUG_INFO = NO; 483 | SDKROOT = iphoneos; 484 | VALIDATE_PRODUCT = YES; 485 | }; 486 | name = Release; 487 | }; 488 | 918E78621F1F4EE100298F79 /* Debug */ = { 489 | isa = XCBuildConfiguration; 490 | buildSettings = { 491 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 492 | DEVELOPMENT_TEAM = 9H2RBN3WMR; 493 | INFOPLIST_FILE = XYTableViewNoDataViewDemo/Info.plist; 494 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 495 | PRODUCT_BUNDLE_IDENTIFIER = com.hanyx.XYTableViewNoDataViewDemo; 496 | PRODUCT_NAME = "$(TARGET_NAME)"; 497 | }; 498 | name = Debug; 499 | }; 500 | 918E78631F1F4EE100298F79 /* Release */ = { 501 | isa = XCBuildConfiguration; 502 | buildSettings = { 503 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 504 | DEVELOPMENT_TEAM = 9H2RBN3WMR; 505 | INFOPLIST_FILE = XYTableViewNoDataViewDemo/Info.plist; 506 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 507 | PRODUCT_BUNDLE_IDENTIFIER = com.hanyx.XYTableViewNoDataViewDemo; 508 | PRODUCT_NAME = "$(TARGET_NAME)"; 509 | }; 510 | name = Release; 511 | }; 512 | /* End XCBuildConfiguration section */ 513 | 514 | /* Begin XCConfigurationList section */ 515 | 918E78451F1F4EE000298F79 /* Build configuration list for PBXProject "XYTableViewNoDataViewDemo" */ = { 516 | isa = XCConfigurationList; 517 | buildConfigurations = ( 518 | 918E785F1F1F4EE100298F79 /* Debug */, 519 | 918E78601F1F4EE100298F79 /* Release */, 520 | ); 521 | defaultConfigurationIsVisible = 0; 522 | defaultConfigurationName = Release; 523 | }; 524 | 918E78611F1F4EE100298F79 /* Build configuration list for PBXNativeTarget "XYTableViewNoDataViewDemo" */ = { 525 | isa = XCConfigurationList; 526 | buildConfigurations = ( 527 | 918E78621F1F4EE100298F79 /* Debug */, 528 | 918E78631F1F4EE100298F79 /* Release */, 529 | ); 530 | defaultConfigurationIsVisible = 0; 531 | defaultConfigurationName = Release; 532 | }; 533 | /* End XCConfigurationList section */ 534 | }; 535 | rootObject = 918E78421F1F4EE000298F79 /* Project object */; 536 | } 537 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Assets.xcassets/note_list_no_data.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "笔记.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Assets.xcassets/note_list_no_data.imageset/笔记.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanyx1992/XYTableViewNoDataView/e7de96f22c30959dae5b2146f19cb9f6973af7a2/XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Assets.xcassets/note_list_no_data.imageset/笔记.png -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshAutoFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshFooter.h" 10 | 11 | @interface MJRefreshAutoFooter : MJRefreshFooter 12 | /** 是否自动刷新(默认为YES) */ 13 | @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh; 14 | 15 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ 16 | @property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用triggerAutomaticallyRefreshPercent属性"); 17 | 18 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */ 19 | @property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent; 20 | @end 21 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshAutoFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoFooter.h" 10 | 11 | @interface MJRefreshAutoFooter() 12 | @end 13 | 14 | @implementation MJRefreshAutoFooter 15 | 16 | #pragma mark - 初始化 17 | - (void)willMoveToSuperview:(UIView *)newSuperview 18 | { 19 | [super willMoveToSuperview:newSuperview]; 20 | 21 | if (newSuperview) { // 新的父控件 22 | if (self.hidden == NO) { 23 | self.scrollView.mj_insetB += self.mj_h; 24 | } 25 | 26 | // 设置位置 27 | self.mj_y = _scrollView.mj_contentH; 28 | } else { // 被移除了 29 | if (self.hidden == NO) { 30 | self.scrollView.mj_insetB -= self.mj_h; 31 | } 32 | } 33 | } 34 | 35 | #pragma mark - 过期方法 36 | - (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh 37 | { 38 | self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh; 39 | } 40 | 41 | - (CGFloat)appearencePercentTriggerAutoRefresh 42 | { 43 | return self.triggerAutomaticallyRefreshPercent; 44 | } 45 | 46 | #pragma mark - 实现父类的方法 47 | - (void)prepare 48 | { 49 | [super prepare]; 50 | 51 | // 默认底部控件100%出现时才会自动刷新 52 | self.triggerAutomaticallyRefreshPercent = 1.0; 53 | 54 | // 设置为默认状态 55 | self.automaticallyRefresh = YES; 56 | } 57 | 58 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change 59 | { 60 | [super scrollViewContentSizeDidChange:change]; 61 | 62 | // 设置位置 63 | self.mj_y = self.scrollView.mj_contentH; 64 | } 65 | 66 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 67 | { 68 | [super scrollViewContentOffsetDidChange:change]; 69 | 70 | if (self.state != MJRefreshStateIdle || !self.automaticallyRefresh || self.mj_y == 0) return; 71 | 72 | if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕 73 | // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理 74 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) { 75 | // 防止手松开时连续调用 76 | CGPoint old = [change[@"old"] CGPointValue]; 77 | CGPoint new = [change[@"new"] CGPointValue]; 78 | if (new.y <= old.y) return; 79 | 80 | // 当底部刷新控件完全出现时,才刷新 81 | [self beginRefreshing]; 82 | } 83 | } 84 | } 85 | 86 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change 87 | { 88 | [super scrollViewPanStateDidChange:change]; 89 | 90 | if (self.state != MJRefreshStateIdle) return; 91 | 92 | if (_scrollView.panGestureRecognizer.state == UIGestureRecognizerStateEnded) {// 手松开 93 | if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕 94 | if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽 95 | [self beginRefreshing]; 96 | } 97 | } else { // 超出一个屏幕 98 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) { 99 | [self beginRefreshing]; 100 | } 101 | } 102 | } 103 | } 104 | 105 | - (void)setState:(MJRefreshState)state 106 | { 107 | MJRefreshCheckState 108 | 109 | if (state == MJRefreshStateRefreshing) { 110 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 111 | [self executeRefreshingCallback]; 112 | }); 113 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 114 | if (MJRefreshStateRefreshing == oldState) { 115 | if (self.endRefreshingCompletionBlock) { 116 | self.endRefreshingCompletionBlock(); 117 | } 118 | } 119 | } 120 | } 121 | 122 | - (void)setHidden:(BOOL)hidden 123 | { 124 | BOOL lastHidden = self.isHidden; 125 | 126 | [super setHidden:hidden]; 127 | 128 | if (!lastHidden && hidden) { 129 | self.state = MJRefreshStateIdle; 130 | 131 | self.scrollView.mj_insetB -= self.mj_h; 132 | } else if (lastHidden && !hidden) { 133 | self.scrollView.mj_insetB += self.mj_h; 134 | 135 | // 设置位置 136 | self.mj_y = _scrollView.mj_contentH; 137 | } 138 | } 139 | @end 140 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshBackFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshFooter.h" 10 | 11 | @interface MJRefreshBackFooter : MJRefreshFooter 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshBackFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackFooter.h" 10 | 11 | @interface MJRefreshBackFooter() 12 | @property (assign, nonatomic) NSInteger lastRefreshCount; 13 | @property (assign, nonatomic) CGFloat lastBottomDelta; 14 | @end 15 | 16 | @implementation MJRefreshBackFooter 17 | 18 | #pragma mark - 初始化 19 | - (void)willMoveToSuperview:(UIView *)newSuperview 20 | { 21 | [super willMoveToSuperview:newSuperview]; 22 | 23 | [self scrollViewContentSizeDidChange:nil]; 24 | } 25 | 26 | #pragma mark - 实现父类的方法 27 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 28 | { 29 | [super scrollViewContentOffsetDidChange:change]; 30 | 31 | // 如果正在刷新,直接返回 32 | if (self.state == MJRefreshStateRefreshing) return; 33 | 34 | _scrollViewOriginalInset = self.scrollView.mj_inset; 35 | 36 | // 当前的contentOffset 37 | CGFloat currentOffsetY = self.scrollView.mj_offsetY; 38 | // 尾部控件刚好出现的offsetY 39 | CGFloat happenOffsetY = [self happenOffsetY]; 40 | // 如果是向下滚动到看不见尾部控件,直接返回 41 | if (currentOffsetY <= happenOffsetY) return; 42 | 43 | CGFloat pullingPercent = (currentOffsetY - happenOffsetY) / self.mj_h; 44 | 45 | // 如果已全部加载,仅设置pullingPercent,然后返回 46 | if (self.state == MJRefreshStateNoMoreData) { 47 | self.pullingPercent = pullingPercent; 48 | return; 49 | } 50 | 51 | if (self.scrollView.isDragging) { 52 | self.pullingPercent = pullingPercent; 53 | // 普通 和 即将刷新 的临界点 54 | CGFloat normal2pullingOffsetY = happenOffsetY + self.mj_h; 55 | 56 | if (self.state == MJRefreshStateIdle && currentOffsetY > normal2pullingOffsetY) { 57 | // 转为即将刷新状态 58 | self.state = MJRefreshStatePulling; 59 | } else if (self.state == MJRefreshStatePulling && currentOffsetY <= normal2pullingOffsetY) { 60 | // 转为普通状态 61 | self.state = MJRefreshStateIdle; 62 | } 63 | } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 64 | // 开始刷新 65 | [self beginRefreshing]; 66 | } else if (pullingPercent < 1) { 67 | self.pullingPercent = pullingPercent; 68 | } 69 | } 70 | 71 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change 72 | { 73 | [super scrollViewContentSizeDidChange:change]; 74 | 75 | // 内容的高度 76 | CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom; 77 | // 表格的高度 78 | CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom; 79 | // 设置位置和尺寸 80 | self.mj_y = MAX(contentHeight, scrollHeight); 81 | } 82 | 83 | - (void)setState:(MJRefreshState)state 84 | { 85 | MJRefreshCheckState 86 | 87 | // 根据状态来设置属性 88 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 89 | // 刷新完毕 90 | if (MJRefreshStateRefreshing == oldState) { 91 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 92 | self.scrollView.mj_insetB -= self.lastBottomDelta; 93 | 94 | // 自动调整透明度 95 | if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; 96 | } completion:^(BOOL finished) { 97 | self.pullingPercent = 0.0; 98 | 99 | if (self.endRefreshingCompletionBlock) { 100 | self.endRefreshingCompletionBlock(); 101 | } 102 | }]; 103 | } 104 | 105 | CGFloat deltaH = [self heightForContentBreakView]; 106 | // 刚刷新完毕 107 | if (MJRefreshStateRefreshing == oldState && deltaH > 0 && self.scrollView.mj_totalDataCount != self.lastRefreshCount) { 108 | self.scrollView.mj_offsetY = self.scrollView.mj_offsetY; 109 | } 110 | } else if (state == MJRefreshStateRefreshing) { 111 | // 记录刷新前的数量 112 | self.lastRefreshCount = self.scrollView.mj_totalDataCount; 113 | 114 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 115 | CGFloat bottom = self.mj_h + self.scrollViewOriginalInset.bottom; 116 | CGFloat deltaH = [self heightForContentBreakView]; 117 | if (deltaH < 0) { // 如果内容高度小于view的高度 118 | bottom -= deltaH; 119 | } 120 | self.lastBottomDelta = bottom - self.scrollView.mj_insetB; 121 | self.scrollView.mj_insetB = bottom; 122 | self.scrollView.mj_offsetY = [self happenOffsetY] + self.mj_h; 123 | } completion:^(BOOL finished) { 124 | [self executeRefreshingCallback]; 125 | }]; 126 | } 127 | } 128 | #pragma mark - 私有方法 129 | #pragma mark 获得scrollView的内容 超出 view 的高度 130 | - (CGFloat)heightForContentBreakView 131 | { 132 | CGFloat h = self.scrollView.frame.size.height - self.scrollViewOriginalInset.bottom - self.scrollViewOriginalInset.top; 133 | return self.scrollView.contentSize.height - h; 134 | } 135 | 136 | #pragma mark 刚好看到上拉刷新控件时的contentOffset.y 137 | - (CGFloat)happenOffsetY 138 | { 139 | CGFloat deltaH = [self heightForContentBreakView]; 140 | if (deltaH > 0) { 141 | return deltaH - self.scrollViewOriginalInset.top; 142 | } else { 143 | return - self.scrollViewOriginalInset.top; 144 | } 145 | } 146 | @end 147 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshComponent.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshComponent.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 刷新控件的基类 9 | 10 | #import 11 | #import "MJRefreshConst.h" 12 | #import "UIView+MJExtension.h" 13 | #import "UIScrollView+MJExtension.h" 14 | #import "UIScrollView+MJRefresh.h" 15 | #import "NSBundle+MJRefresh.h" 16 | 17 | /** 刷新控件的状态 */ 18 | typedef NS_ENUM(NSInteger, MJRefreshState) { 19 | /** 普通闲置状态 */ 20 | MJRefreshStateIdle = 1, 21 | /** 松开就可以进行刷新的状态 */ 22 | MJRefreshStatePulling, 23 | /** 正在刷新中的状态 */ 24 | MJRefreshStateRefreshing, 25 | /** 即将刷新的状态 */ 26 | MJRefreshStateWillRefresh, 27 | /** 所有数据加载完毕,没有更多的数据了 */ 28 | MJRefreshStateNoMoreData 29 | }; 30 | 31 | /** 进入刷新状态的回调 */ 32 | typedef void (^MJRefreshComponentRefreshingBlock)(void); 33 | /** 开始刷新后的回调(进入刷新状态后的回调) */ 34 | typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(void); 35 | /** 结束刷新后的回调 */ 36 | typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void); 37 | 38 | /** 刷新控件的基类 */ 39 | @interface MJRefreshComponent : UIView 40 | { 41 | /** 记录scrollView刚开始的inset */ 42 | UIEdgeInsets _scrollViewOriginalInset; 43 | /** 父控件 */ 44 | __weak UIScrollView *_scrollView; 45 | } 46 | #pragma mark - 刷新回调 47 | /** 正在刷新的回调 */ 48 | @property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock; 49 | /** 设置回调对象和回调方法 */ 50 | - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action; 51 | 52 | /** 回调对象 */ 53 | @property (weak, nonatomic) id refreshingTarget; 54 | /** 回调方法 */ 55 | @property (assign, nonatomic) SEL refreshingAction; 56 | /** 触发回调(交给子类去调用) */ 57 | - (void)executeRefreshingCallback; 58 | 59 | #pragma mark - 刷新状态控制 60 | /** 进入刷新状态 */ 61 | - (void)beginRefreshing; 62 | - (void)beginRefreshingWithCompletionBlock:(void (^)(void))completionBlock; 63 | /** 开始刷新后的回调(进入刷新状态后的回调) */ 64 | @property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock; 65 | /** 结束刷新的回调 */ 66 | @property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock; 67 | /** 结束刷新状态 */ 68 | - (void)endRefreshing; 69 | - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock; 70 | /** 是否正在刷新 */ 71 | @property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing; 72 | //- (BOOL)isRefreshing; 73 | /** 刷新状态 一般交给子类内部实现 */ 74 | @property (assign, nonatomic) MJRefreshState state; 75 | 76 | #pragma mark - 交给子类去访问 77 | /** 记录scrollView刚开始的inset */ 78 | @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset; 79 | /** 父控件 */ 80 | @property (weak, nonatomic, readonly) UIScrollView *scrollView; 81 | 82 | #pragma mark - 交给子类们去实现 83 | /** 初始化 */ 84 | - (void)prepare NS_REQUIRES_SUPER; 85 | /** 摆放子控件frame */ 86 | - (void)placeSubviews NS_REQUIRES_SUPER; 87 | /** 当scrollView的contentOffset发生改变的时候调用 */ 88 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 89 | /** 当scrollView的contentSize发生改变的时候调用 */ 90 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 91 | /** 当scrollView的拖拽状态发生改变的时候调用 */ 92 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER; 93 | 94 | 95 | #pragma mark - 其他 96 | /** 拉拽的百分比(交给子类重写) */ 97 | @property (assign, nonatomic) CGFloat pullingPercent; 98 | /** 根据拖拽比例自动切换透明度 */ 99 | @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性"); 100 | /** 根据拖拽比例自动切换透明度 */ 101 | @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha; 102 | @end 103 | 104 | @interface UILabel(MJRefresh) 105 | + (instancetype)mj_label; 106 | - (CGFloat)mj_textWith; 107 | @end 108 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshComponent.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshComponent.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "MJRefreshComponent.h" 11 | #import "MJRefreshConst.h" 12 | 13 | @interface MJRefreshComponent() 14 | @property (strong, nonatomic) UIPanGestureRecognizer *pan; 15 | @end 16 | 17 | @implementation MJRefreshComponent 18 | #pragma mark - 初始化 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | if (self = [super initWithFrame:frame]) { 22 | // 准备工作 23 | [self prepare]; 24 | 25 | // 默认是普通状态 26 | self.state = MJRefreshStateIdle; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)prepare 32 | { 33 | // 基本属性 34 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 35 | self.backgroundColor = [UIColor clearColor]; 36 | } 37 | 38 | - (void)layoutSubviews 39 | { 40 | [self placeSubviews]; 41 | 42 | [super layoutSubviews]; 43 | } 44 | 45 | - (void)placeSubviews{} 46 | 47 | - (void)willMoveToSuperview:(UIView *)newSuperview 48 | { 49 | [super willMoveToSuperview:newSuperview]; 50 | 51 | // 如果不是UIScrollView,不做任何事情 52 | if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return; 53 | 54 | // 旧的父控件移除监听 55 | [self removeObservers]; 56 | 57 | if (newSuperview) { // 新的父控件 58 | // 设置宽度 59 | self.mj_w = newSuperview.mj_w; 60 | // 设置位置 61 | self.mj_x = -_scrollView.mj_insetL; 62 | 63 | // 记录UIScrollView 64 | _scrollView = (UIScrollView *)newSuperview; 65 | // 设置永远支持垂直弹簧效果 66 | _scrollView.alwaysBounceVertical = YES; 67 | // 记录UIScrollView最开始的contentInset 68 | _scrollViewOriginalInset = _scrollView.mj_inset; 69 | 70 | // 添加监听 71 | [self addObservers]; 72 | } 73 | } 74 | 75 | - (void)drawRect:(CGRect)rect 76 | { 77 | [super drawRect:rect]; 78 | 79 | if (self.state == MJRefreshStateWillRefresh) { 80 | // 预防view还没显示出来就调用了beginRefreshing 81 | self.state = MJRefreshStateRefreshing; 82 | } 83 | } 84 | 85 | #pragma mark - KVO监听 86 | - (void)addObservers 87 | { 88 | NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; 89 | [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentOffset options:options context:nil]; 90 | [self.scrollView addObserver:self forKeyPath:MJRefreshKeyPathContentSize options:options context:nil]; 91 | self.pan = self.scrollView.panGestureRecognizer; 92 | [self.pan addObserver:self forKeyPath:MJRefreshKeyPathPanState options:options context:nil]; 93 | } 94 | 95 | - (void)removeObservers 96 | { 97 | [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentOffset]; 98 | [self.superview removeObserver:self forKeyPath:MJRefreshKeyPathContentSize]; 99 | [self.pan removeObserver:self forKeyPath:MJRefreshKeyPathPanState]; 100 | self.pan = nil; 101 | } 102 | 103 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 104 | { 105 | // 遇到这些情况就直接返回 106 | if (!self.userInteractionEnabled) return; 107 | 108 | // 这个就算看不见也需要处理 109 | if ([keyPath isEqualToString:MJRefreshKeyPathContentSize]) { 110 | [self scrollViewContentSizeDidChange:change]; 111 | } 112 | 113 | // 看不见 114 | if (self.hidden) return; 115 | if ([keyPath isEqualToString:MJRefreshKeyPathContentOffset]) { 116 | [self scrollViewContentOffsetDidChange:change]; 117 | } else if ([keyPath isEqualToString:MJRefreshKeyPathPanState]) { 118 | [self scrollViewPanStateDidChange:change]; 119 | } 120 | } 121 | 122 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change{} 123 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change{} 124 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change{} 125 | 126 | #pragma mark - 公共方法 127 | #pragma mark 设置回调对象和回调方法 128 | - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action 129 | { 130 | self.refreshingTarget = target; 131 | self.refreshingAction = action; 132 | } 133 | 134 | - (void)setState:(MJRefreshState)state 135 | { 136 | _state = state; 137 | 138 | // 加入主队列的目的是等setState:方法调用完毕、设置完文字后再去布局子控件 139 | dispatch_async(dispatch_get_main_queue(), ^{ 140 | [self setNeedsLayout]; 141 | }); 142 | } 143 | 144 | #pragma mark 进入刷新状态 145 | - (void)beginRefreshing 146 | { 147 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 148 | self.alpha = 1.0; 149 | }]; 150 | self.pullingPercent = 1.0; 151 | // 只要正在刷新,就完全显示 152 | if (self.window) { 153 | self.state = MJRefreshStateRefreshing; 154 | } else { 155 | // 预防正在刷新中时,调用本方法使得header inset回置失败 156 | if (self.state != MJRefreshStateRefreshing) { 157 | self.state = MJRefreshStateWillRefresh; 158 | // 刷新(预防从另一个控制器回到这个控制器的情况,回来要重新刷新一下) 159 | [self setNeedsDisplay]; 160 | } 161 | } 162 | } 163 | 164 | - (void)beginRefreshingWithCompletionBlock:(void (^)(void))completionBlock 165 | { 166 | self.beginRefreshingCompletionBlock = completionBlock; 167 | 168 | [self beginRefreshing]; 169 | } 170 | 171 | #pragma mark 结束刷新状态 172 | - (void)endRefreshing 173 | { 174 | dispatch_async(dispatch_get_main_queue(), ^{ 175 | self.state = MJRefreshStateIdle; 176 | }); 177 | } 178 | 179 | - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock 180 | { 181 | self.endRefreshingCompletionBlock = completionBlock; 182 | 183 | [self endRefreshing]; 184 | } 185 | 186 | #pragma mark 是否正在刷新 187 | - (BOOL)isRefreshing 188 | { 189 | return self.state == MJRefreshStateRefreshing || self.state == MJRefreshStateWillRefresh; 190 | } 191 | 192 | #pragma mark 自动切换透明度 193 | - (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha 194 | { 195 | self.automaticallyChangeAlpha = autoChangeAlpha; 196 | } 197 | 198 | - (BOOL)isAutoChangeAlpha 199 | { 200 | return self.isAutomaticallyChangeAlpha; 201 | } 202 | 203 | - (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha 204 | { 205 | _automaticallyChangeAlpha = automaticallyChangeAlpha; 206 | 207 | if (self.isRefreshing) return; 208 | 209 | if (automaticallyChangeAlpha) { 210 | self.alpha = self.pullingPercent; 211 | } else { 212 | self.alpha = 1.0; 213 | } 214 | } 215 | 216 | #pragma mark 根据拖拽进度设置透明度 217 | - (void)setPullingPercent:(CGFloat)pullingPercent 218 | { 219 | _pullingPercent = pullingPercent; 220 | 221 | if (self.isRefreshing) return; 222 | 223 | if (self.isAutomaticallyChangeAlpha) { 224 | self.alpha = pullingPercent; 225 | } 226 | } 227 | 228 | #pragma mark - 内部方法 229 | - (void)executeRefreshingCallback 230 | { 231 | dispatch_async(dispatch_get_main_queue(), ^{ 232 | if (self.refreshingBlock) { 233 | self.refreshingBlock(); 234 | } 235 | if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) { 236 | MJRefreshMsgSend(MJRefreshMsgTarget(self.refreshingTarget), self.refreshingAction, self); 237 | } 238 | if (self.beginRefreshingCompletionBlock) { 239 | self.beginRefreshingCompletionBlock(); 240 | } 241 | }); 242 | } 243 | @end 244 | 245 | @implementation UILabel(MJRefresh) 246 | + (instancetype)mj_label 247 | { 248 | UILabel *label = [[self alloc] init]; 249 | label.font = MJRefreshLabelFont; 250 | label.textColor = MJRefreshLabelTextColor; 251 | label.autoresizingMask = UIViewAutoresizingFlexibleWidth; 252 | label.textAlignment = NSTextAlignmentCenter; 253 | label.backgroundColor = [UIColor clearColor]; 254 | return label; 255 | } 256 | 257 | - (CGFloat)mj_textWith { 258 | CGFloat stringWidth = 0; 259 | CGSize size = CGSizeMake(MAXFLOAT, MAXFLOAT); 260 | if (self.text.length > 0) { 261 | #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 262 | stringWidth =[self.text 263 | boundingRectWithSize:size 264 | options:NSStringDrawingUsesLineFragmentOrigin 265 | attributes:@{NSFontAttributeName:self.font} 266 | context:nil].size.width; 267 | #else 268 | 269 | stringWidth = [self.text sizeWithFont:self.font 270 | constrainedToSize:size 271 | lineBreakMode:NSLineBreakByCharWrapping].width; 272 | #endif 273 | } 274 | return stringWidth; 275 | } 276 | @end 277 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshFooter.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshFooter.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/5. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 上拉刷新控件 9 | 10 | #import "MJRefreshComponent.h" 11 | 12 | @interface MJRefreshFooter : MJRefreshComponent 13 | /** 创建footer */ 14 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; 15 | /** 创建footer */ 16 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; 17 | 18 | /** 提示没有更多的数据 */ 19 | - (void)endRefreshingWithNoMoreData; 20 | - (void)noticeNoMoreData MJRefreshDeprecated("使用endRefreshingWithNoMoreData"); 21 | 22 | /** 重置没有更多的数据(消除没有更多数据的状态) */ 23 | - (void)resetNoMoreData; 24 | 25 | /** 忽略多少scrollView的contentInset的bottom */ 26 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom; 27 | 28 | /** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏。默认是NO) */ 29 | @property (assign, nonatomic, getter=isAutomaticallyHidden) BOOL automaticallyHidden; 30 | @end 31 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshFooter.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshFooter.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/5. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "MJRefreshFooter.h" 11 | 12 | @interface MJRefreshFooter() 13 | 14 | @end 15 | 16 | @implementation MJRefreshFooter 17 | #pragma mark - 构造方法 18 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock 19 | { 20 | MJRefreshFooter *cmp = [[self alloc] init]; 21 | cmp.refreshingBlock = refreshingBlock; 22 | return cmp; 23 | } 24 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action 25 | { 26 | MJRefreshFooter *cmp = [[self alloc] init]; 27 | [cmp setRefreshingTarget:target refreshingAction:action]; 28 | return cmp; 29 | } 30 | 31 | #pragma mark - 重写父类的方法 32 | - (void)prepare 33 | { 34 | [super prepare]; 35 | 36 | // 设置自己的高度 37 | self.mj_h = MJRefreshFooterHeight; 38 | 39 | // 默认不会自动隐藏 40 | self.automaticallyHidden = NO; 41 | } 42 | 43 | - (void)willMoveToSuperview:(UIView *)newSuperview 44 | { 45 | [super willMoveToSuperview:newSuperview]; 46 | 47 | if (newSuperview) { 48 | // 监听scrollView数据的变化 49 | if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) { 50 | [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) { 51 | if (self.isAutomaticallyHidden) { 52 | self.hidden = (totalDataCount == 0); 53 | } 54 | }]; 55 | } 56 | } 57 | } 58 | 59 | #pragma mark - 公共方法 60 | - (void)endRefreshingWithNoMoreData 61 | { 62 | dispatch_async(dispatch_get_main_queue(), ^{ 63 | self.state = MJRefreshStateNoMoreData; 64 | }); 65 | } 66 | 67 | - (void)noticeNoMoreData 68 | { 69 | [self endRefreshingWithNoMoreData]; 70 | } 71 | 72 | - (void)resetNoMoreData 73 | { 74 | dispatch_async(dispatch_get_main_queue(), ^{ 75 | self.state = MJRefreshStateIdle; 76 | }); 77 | } 78 | @end 79 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshHeader.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshHeader.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 下拉刷新控件:负责监控用户下拉的状态 9 | 10 | #import "MJRefreshComponent.h" 11 | 12 | @interface MJRefreshHeader : MJRefreshComponent 13 | /** 创建header */ 14 | + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock; 15 | /** 创建header */ 16 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action; 17 | 18 | /** 这个key用来存储上一次下拉刷新成功的时间 */ 19 | @property (copy, nonatomic) NSString *lastUpdatedTimeKey; 20 | /** 上一次下拉刷新成功的时间 */ 21 | @property (strong, nonatomic, readonly) NSDate *lastUpdatedTime; 22 | 23 | /** 忽略多少scrollView的contentInset的top */ 24 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop; 25 | @end 26 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Base/MJRefreshHeader.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // MJRefreshHeader.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "MJRefreshHeader.h" 11 | 12 | @interface MJRefreshHeader() 13 | @property (assign, nonatomic) CGFloat insetTDelta; 14 | @end 15 | 16 | @implementation MJRefreshHeader 17 | #pragma mark - 构造方法 18 | + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock 19 | { 20 | MJRefreshHeader *cmp = [[self alloc] init]; 21 | cmp.refreshingBlock = refreshingBlock; 22 | return cmp; 23 | } 24 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action 25 | { 26 | MJRefreshHeader *cmp = [[self alloc] init]; 27 | [cmp setRefreshingTarget:target refreshingAction:action]; 28 | return cmp; 29 | } 30 | 31 | #pragma mark - 覆盖父类的方法 32 | - (void)prepare 33 | { 34 | [super prepare]; 35 | 36 | // 设置key 37 | self.lastUpdatedTimeKey = MJRefreshHeaderLastUpdatedTimeKey; 38 | 39 | // 设置高度 40 | self.mj_h = MJRefreshHeaderHeight; 41 | } 42 | 43 | - (void)placeSubviews 44 | { 45 | [super placeSubviews]; 46 | 47 | // 设置y值(当自己的高度发生改变了,肯定要重新调整Y值,所以放到placeSubviews方法中设置y值) 48 | self.mj_y = - self.mj_h - self.ignoredScrollViewContentInsetTop; 49 | } 50 | 51 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change 52 | { 53 | [super scrollViewContentOffsetDidChange:change]; 54 | 55 | // 在刷新的refreshing状态 56 | if (self.state == MJRefreshStateRefreshing) { 57 | if (self.window == nil) return; 58 | 59 | // sectionheader停留解决 60 | CGFloat insetT = - self.scrollView.mj_offsetY > _scrollViewOriginalInset.top ? - self.scrollView.mj_offsetY : _scrollViewOriginalInset.top; 61 | insetT = insetT > self.mj_h + _scrollViewOriginalInset.top ? self.mj_h + _scrollViewOriginalInset.top : insetT; 62 | self.scrollView.mj_insetT = insetT; 63 | 64 | self.insetTDelta = _scrollViewOriginalInset.top - insetT; 65 | return; 66 | } 67 | 68 | // 跳转到下一个控制器时,contentInset可能会变 69 | _scrollViewOriginalInset = self.scrollView.mj_inset; 70 | 71 | // 当前的contentOffset 72 | CGFloat offsetY = self.scrollView.mj_offsetY; 73 | // 头部控件刚好出现的offsetY 74 | CGFloat happenOffsetY = - self.scrollViewOriginalInset.top; 75 | 76 | // 如果是向上滚动到看不见头部控件,直接返回 77 | // >= -> > 78 | if (offsetY > happenOffsetY) return; 79 | 80 | // 普通 和 即将刷新 的临界点 81 | CGFloat normal2pullingOffsetY = happenOffsetY - self.mj_h; 82 | CGFloat pullingPercent = (happenOffsetY - offsetY) / self.mj_h; 83 | 84 | if (self.scrollView.isDragging) { // 如果正在拖拽 85 | self.pullingPercent = pullingPercent; 86 | if (self.state == MJRefreshStateIdle && offsetY < normal2pullingOffsetY) { 87 | // 转为即将刷新状态 88 | self.state = MJRefreshStatePulling; 89 | } else if (self.state == MJRefreshStatePulling && offsetY >= normal2pullingOffsetY) { 90 | // 转为普通状态 91 | self.state = MJRefreshStateIdle; 92 | } 93 | } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开 94 | // 开始刷新 95 | [self beginRefreshing]; 96 | } else if (pullingPercent < 1) { 97 | self.pullingPercent = pullingPercent; 98 | } 99 | } 100 | 101 | - (void)setState:(MJRefreshState)state 102 | { 103 | MJRefreshCheckState 104 | 105 | // 根据状态做事情 106 | if (state == MJRefreshStateIdle) { 107 | if (oldState != MJRefreshStateRefreshing) return; 108 | 109 | // 保存刷新时间 110 | [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:self.lastUpdatedTimeKey]; 111 | [[NSUserDefaults standardUserDefaults] synchronize]; 112 | 113 | // 恢复inset和offset 114 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 115 | self.scrollView.mj_insetT += self.insetTDelta; 116 | 117 | // 自动调整透明度 118 | if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0; 119 | } completion:^(BOOL finished) { 120 | self.pullingPercent = 0.0; 121 | 122 | if (self.endRefreshingCompletionBlock) { 123 | self.endRefreshingCompletionBlock(); 124 | } 125 | }]; 126 | } else if (state == MJRefreshStateRefreshing) { 127 | dispatch_async(dispatch_get_main_queue(), ^{ 128 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 129 | CGFloat top = self.scrollViewOriginalInset.top + self.mj_h; 130 | // 增加滚动区域top 131 | self.scrollView.mj_insetT = top; 132 | // 设置滚动位置 133 | CGPoint offset = self.scrollView.contentOffset; 134 | offset.y = -top; 135 | [self.scrollView setContentOffset:offset animated:NO]; 136 | } completion:^(BOOL finished) { 137 | [self executeRefreshingCallback]; 138 | }]; 139 | }); 140 | } 141 | } 142 | 143 | #pragma mark - 公共方法 144 | - (NSDate *)lastUpdatedTime 145 | { 146 | return [[NSUserDefaults standardUserDefaults] objectForKey:self.lastUpdatedTimeKey]; 147 | } 148 | @end 149 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoGifFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoGifFooter : MJRefreshAutoStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoGifFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoGifFooter.h" 10 | 11 | @interface MJRefreshAutoGifFooter() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshAutoGifFooter 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)placeSubviews 78 | { 79 | [super placeSubviews]; 80 | 81 | if (self.gifView.constraints.count) return; 82 | 83 | self.gifView.frame = self.bounds; 84 | if (self.isRefreshingTitleHidden) { 85 | self.gifView.contentMode = UIViewContentModeCenter; 86 | } else { 87 | self.gifView.contentMode = UIViewContentModeRight; 88 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; 89 | } 90 | } 91 | 92 | - (void)setState:(MJRefreshState)state 93 | { 94 | MJRefreshCheckState 95 | 96 | // 根据状态做事情 97 | if (state == MJRefreshStateRefreshing) { 98 | NSArray *images = self.stateImages[@(state)]; 99 | if (images.count == 0) return; 100 | [self.gifView stopAnimating]; 101 | 102 | self.gifView.hidden = NO; 103 | if (images.count == 1) { // 单张图片 104 | self.gifView.image = [images lastObject]; 105 | } else { // 多张图片 106 | self.gifView.animationImages = images; 107 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 108 | [self.gifView startAnimating]; 109 | } 110 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 111 | [self.gifView stopAnimating]; 112 | self.gifView.hidden = YES; 113 | } 114 | } 115 | @end 116 | 117 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoNormalFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoNormalFooter : MJRefreshAutoStateFooter 12 | /** 菊花的样式 */ 13 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 14 | @end 15 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoNormalFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoNormalFooter.h" 10 | 11 | @interface MJRefreshAutoNormalFooter() 12 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 13 | @end 14 | 15 | @implementation MJRefreshAutoNormalFooter 16 | #pragma mark - 懒加载子控件 17 | - (UIActivityIndicatorView *)loadingView 18 | { 19 | if (!_loadingView) { 20 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 21 | loadingView.hidesWhenStopped = YES; 22 | [self addSubview:_loadingView = loadingView]; 23 | } 24 | return _loadingView; 25 | } 26 | 27 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 28 | { 29 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 30 | 31 | self.loadingView = nil; 32 | [self setNeedsLayout]; 33 | } 34 | #pragma mark - 重写父类的方法 35 | - (void)prepare 36 | { 37 | [super prepare]; 38 | 39 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 40 | } 41 | 42 | - (void)placeSubviews 43 | { 44 | [super placeSubviews]; 45 | 46 | if (self.loadingView.constraints.count) return; 47 | 48 | // 圈圈 49 | CGFloat loadingCenterX = self.mj_w * 0.5; 50 | if (!self.isRefreshingTitleHidden) { 51 | loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset; 52 | } 53 | CGFloat loadingCenterY = self.mj_h * 0.5; 54 | self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY); 55 | } 56 | 57 | - (void)setState:(MJRefreshState)state 58 | { 59 | MJRefreshCheckState 60 | 61 | // 根据状态做事情 62 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) { 63 | [self.loadingView stopAnimating]; 64 | } else if (state == MJRefreshStateRefreshing) { 65 | [self.loadingView startAnimating]; 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoStateFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoFooter.h" 10 | 11 | @interface MJRefreshAutoStateFooter : MJRefreshAutoFooter 12 | /** 文字距离圈圈、箭头的距离 */ 13 | @property (assign, nonatomic) CGFloat labelLeftInset; 14 | /** 显示刷新状态的label */ 15 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 16 | 17 | /** 设置state状态下的文字 */ 18 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 19 | 20 | /** 隐藏刷新状态的文字 */ 21 | @property (assign, nonatomic, getter=isRefreshingTitleHidden) BOOL refreshingTitleHidden; 22 | @end 23 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshAutoStateFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshAutoStateFooter.h" 10 | 11 | @interface MJRefreshAutoStateFooter() 12 | { 13 | /** 显示刷新状态的label */ 14 | __unsafe_unretained UILabel *_stateLabel; 15 | } 16 | /** 所有状态对应的文字 */ 17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 18 | @end 19 | 20 | @implementation MJRefreshAutoStateFooter 21 | #pragma mark - 懒加载 22 | - (NSMutableDictionary *)stateTitles 23 | { 24 | if (!_stateTitles) { 25 | self.stateTitles = [NSMutableDictionary dictionary]; 26 | } 27 | return _stateTitles; 28 | } 29 | 30 | - (UILabel *)stateLabel 31 | { 32 | if (!_stateLabel) { 33 | [self addSubview:_stateLabel = [UILabel mj_label]]; 34 | } 35 | return _stateLabel; 36 | } 37 | 38 | #pragma mark - 公共方法 39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 40 | { 41 | if (title == nil) return; 42 | self.stateTitles[@(state)] = title; 43 | self.stateLabel.text = self.stateTitles[@(self.state)]; 44 | } 45 | 46 | #pragma mark - 私有方法 47 | - (void)stateLabelClick 48 | { 49 | if (self.state == MJRefreshStateIdle) { 50 | [self beginRefreshing]; 51 | } 52 | } 53 | 54 | #pragma mark - 重写父类的方法 55 | - (void)prepare 56 | { 57 | [super prepare]; 58 | 59 | // 初始化间距 60 | self.labelLeftInset = MJRefreshLabelLeftInset; 61 | 62 | // 初始化文字 63 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle]; 64 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing]; 65 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; 66 | 67 | // 监听label 68 | self.stateLabel.userInteractionEnabled = YES; 69 | [self.stateLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateLabelClick)]]; 70 | } 71 | 72 | - (void)placeSubviews 73 | { 74 | [super placeSubviews]; 75 | 76 | if (self.stateLabel.constraints.count) return; 77 | 78 | // 状态标签 79 | self.stateLabel.frame = self.bounds; 80 | } 81 | 82 | - (void)setState:(MJRefreshState)state 83 | { 84 | MJRefreshCheckState 85 | 86 | if (self.isRefreshingTitleHidden && state == MJRefreshStateRefreshing) { 87 | self.stateLabel.text = nil; 88 | } else { 89 | self.stateLabel.text = self.stateTitles[@(state)]; 90 | } 91 | } 92 | @end -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackGifFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackGifFooter : MJRefreshBackStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackGifFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackGifFooter.h" 10 | 11 | @interface MJRefreshBackGifFooter() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshBackGifFooter 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)setPullingPercent:(CGFloat)pullingPercent 78 | { 79 | [super setPullingPercent:pullingPercent]; 80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; 81 | if (self.state != MJRefreshStateIdle || images.count == 0) return; 82 | [self.gifView stopAnimating]; 83 | NSUInteger index = images.count * pullingPercent; 84 | if (index >= images.count) index = images.count - 1; 85 | self.gifView.image = images[index]; 86 | } 87 | 88 | - (void)placeSubviews 89 | { 90 | [super placeSubviews]; 91 | 92 | if (self.gifView.constraints.count) return; 93 | 94 | self.gifView.frame = self.bounds; 95 | if (self.stateLabel.hidden) { 96 | self.gifView.contentMode = UIViewContentModeCenter; 97 | } else { 98 | self.gifView.contentMode = UIViewContentModeRight; 99 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5; 100 | } 101 | } 102 | 103 | - (void)setState:(MJRefreshState)state 104 | { 105 | MJRefreshCheckState 106 | 107 | // 根据状态做事情 108 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { 109 | NSArray *images = self.stateImages[@(state)]; 110 | if (images.count == 0) return; 111 | 112 | self.gifView.hidden = NO; 113 | [self.gifView stopAnimating]; 114 | if (images.count == 1) { // 单张图片 115 | self.gifView.image = [images lastObject]; 116 | } else { // 多张图片 117 | self.gifView.animationImages = images; 118 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 119 | [self.gifView startAnimating]; 120 | } 121 | } else if (state == MJRefreshStateIdle) { 122 | self.gifView.hidden = NO; 123 | } else if (state == MJRefreshStateNoMoreData) { 124 | self.gifView.hidden = YES; 125 | } 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackNormalFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackNormalFooter : MJRefreshBackStateFooter 12 | @property (weak, nonatomic, readonly) UIImageView *arrowView; 13 | /** 菊花的样式 */ 14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 15 | @end 16 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackNormalFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackNormalFooter.h" 10 | #import "NSBundle+MJRefresh.h" 11 | 12 | @interface MJRefreshBackNormalFooter() 13 | { 14 | __unsafe_unretained UIImageView *_arrowView; 15 | } 16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 17 | @end 18 | 19 | @implementation MJRefreshBackNormalFooter 20 | #pragma mark - 懒加载子控件 21 | - (UIImageView *)arrowView 22 | { 23 | if (!_arrowView) { 24 | UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; 25 | [self addSubview:_arrowView = arrowView]; 26 | } 27 | return _arrowView; 28 | } 29 | 30 | 31 | - (UIActivityIndicatorView *)loadingView 32 | { 33 | if (!_loadingView) { 34 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 35 | loadingView.hidesWhenStopped = YES; 36 | [self addSubview:_loadingView = loadingView]; 37 | } 38 | return _loadingView; 39 | } 40 | 41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 42 | { 43 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 44 | 45 | self.loadingView = nil; 46 | [self setNeedsLayout]; 47 | } 48 | #pragma mark - 重写父类的方法 49 | - (void)prepare 50 | { 51 | [super prepare]; 52 | 53 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 54 | } 55 | 56 | - (void)placeSubviews 57 | { 58 | [super placeSubviews]; 59 | 60 | // 箭头的中心点 61 | CGFloat arrowCenterX = self.mj_w * 0.5; 62 | if (!self.stateLabel.hidden) { 63 | arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5; 64 | } 65 | CGFloat arrowCenterY = self.mj_h * 0.5; 66 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); 67 | 68 | // 箭头 69 | if (self.arrowView.constraints.count == 0) { 70 | self.arrowView.mj_size = self.arrowView.image.size; 71 | self.arrowView.center = arrowCenter; 72 | } 73 | 74 | // 圈圈 75 | if (self.loadingView.constraints.count == 0) { 76 | self.loadingView.center = arrowCenter; 77 | } 78 | 79 | self.arrowView.tintColor = self.stateLabel.textColor; 80 | } 81 | 82 | - (void)setState:(MJRefreshState)state 83 | { 84 | MJRefreshCheckState 85 | 86 | // 根据状态做事情 87 | if (state == MJRefreshStateIdle) { 88 | if (oldState == MJRefreshStateRefreshing) { 89 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 90 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 91 | self.loadingView.alpha = 0.0; 92 | } completion:^(BOOL finished) { 93 | self.loadingView.alpha = 1.0; 94 | [self.loadingView stopAnimating]; 95 | 96 | self.arrowView.hidden = NO; 97 | }]; 98 | } else { 99 | self.arrowView.hidden = NO; 100 | [self.loadingView stopAnimating]; 101 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 102 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 103 | }]; 104 | } 105 | } else if (state == MJRefreshStatePulling) { 106 | self.arrowView.hidden = NO; 107 | [self.loadingView stopAnimating]; 108 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 109 | self.arrowView.transform = CGAffineTransformIdentity; 110 | }]; 111 | } else if (state == MJRefreshStateRefreshing) { 112 | self.arrowView.hidden = YES; 113 | [self.loadingView startAnimating]; 114 | } else if (state == MJRefreshStateNoMoreData) { 115 | self.arrowView.hidden = YES; 116 | [self.loadingView stopAnimating]; 117 | } 118 | } 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackStateFooter.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackFooter.h" 10 | 11 | @interface MJRefreshBackStateFooter : MJRefreshBackFooter 12 | /** 文字距离圈圈、箭头的距离 */ 13 | @property (assign, nonatomic) CGFloat labelLeftInset; 14 | /** 显示刷新状态的label */ 15 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 16 | /** 设置state状态下的文字 */ 17 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 18 | 19 | /** 获取state状态下的title */ 20 | - (NSString *)titleForState:(MJRefreshState)state; 21 | @end 22 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshBackStateFooter.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/6/13. 6 | // Copyright © 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshBackStateFooter.h" 10 | 11 | @interface MJRefreshBackStateFooter() 12 | { 13 | /** 显示刷新状态的label */ 14 | __unsafe_unretained UILabel *_stateLabel; 15 | } 16 | /** 所有状态对应的文字 */ 17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 18 | @end 19 | 20 | @implementation MJRefreshBackStateFooter 21 | #pragma mark - 懒加载 22 | - (NSMutableDictionary *)stateTitles 23 | { 24 | if (!_stateTitles) { 25 | self.stateTitles = [NSMutableDictionary dictionary]; 26 | } 27 | return _stateTitles; 28 | } 29 | 30 | - (UILabel *)stateLabel 31 | { 32 | if (!_stateLabel) { 33 | [self addSubview:_stateLabel = [UILabel mj_label]]; 34 | } 35 | return _stateLabel; 36 | } 37 | 38 | #pragma mark - 公共方法 39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 40 | { 41 | if (title == nil) return; 42 | self.stateTitles[@(state)] = title; 43 | self.stateLabel.text = self.stateTitles[@(self.state)]; 44 | } 45 | 46 | - (NSString *)titleForState:(MJRefreshState)state { 47 | return self.stateTitles[@(state)]; 48 | } 49 | 50 | #pragma mark - 重写父类的方法 51 | - (void)prepare 52 | { 53 | [super prepare]; 54 | 55 | // 初始化间距 56 | self.labelLeftInset = MJRefreshLabelLeftInset; 57 | 58 | // 初始化文字 59 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle]; 60 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling]; 61 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing]; 62 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData]; 63 | } 64 | 65 | - (void)placeSubviews 66 | { 67 | [super placeSubviews]; 68 | 69 | if (self.stateLabel.constraints.count) return; 70 | 71 | // 状态标签 72 | self.stateLabel.frame = self.bounds; 73 | } 74 | 75 | - (void)setState:(MJRefreshState)state 76 | { 77 | MJRefreshCheckState 78 | 79 | // 设置状态文字 80 | self.stateLabel.text = self.stateTitles[@(state)]; 81 | } 82 | @end 83 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshGifHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshGifHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshGifHeader : MJRefreshStateHeader 12 | @property (weak, nonatomic, readonly) UIImageView *gifView; 13 | 14 | /** 设置state状态下的动画图片images 动画持续时间duration*/ 15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state; 16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state; 17 | @end 18 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshGifHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshGifHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshGifHeader.h" 10 | 11 | @interface MJRefreshGifHeader() 12 | { 13 | __unsafe_unretained UIImageView *_gifView; 14 | } 15 | /** 所有状态对应的动画图片 */ 16 | @property (strong, nonatomic) NSMutableDictionary *stateImages; 17 | /** 所有状态对应的动画时间 */ 18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations; 19 | @end 20 | 21 | @implementation MJRefreshGifHeader 22 | #pragma mark - 懒加载 23 | - (UIImageView *)gifView 24 | { 25 | if (!_gifView) { 26 | UIImageView *gifView = [[UIImageView alloc] init]; 27 | [self addSubview:_gifView = gifView]; 28 | } 29 | return _gifView; 30 | } 31 | 32 | - (NSMutableDictionary *)stateImages 33 | { 34 | if (!_stateImages) { 35 | self.stateImages = [NSMutableDictionary dictionary]; 36 | } 37 | return _stateImages; 38 | } 39 | 40 | - (NSMutableDictionary *)stateDurations 41 | { 42 | if (!_stateDurations) { 43 | self.stateDurations = [NSMutableDictionary dictionary]; 44 | } 45 | return _stateDurations; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state 50 | { 51 | if (images == nil) return; 52 | 53 | self.stateImages[@(state)] = images; 54 | self.stateDurations[@(state)] = @(duration); 55 | 56 | /* 根据图片设置控件的高度 */ 57 | UIImage *image = [images firstObject]; 58 | if (image.size.height > self.mj_h) { 59 | self.mj_h = image.size.height; 60 | } 61 | } 62 | 63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state 64 | { 65 | [self setImages:images duration:images.count * 0.1 forState:state]; 66 | } 67 | 68 | #pragma mark - 实现父类的方法 69 | - (void)prepare 70 | { 71 | [super prepare]; 72 | 73 | // 初始化间距 74 | self.labelLeftInset = 20; 75 | } 76 | 77 | - (void)setPullingPercent:(CGFloat)pullingPercent 78 | { 79 | [super setPullingPercent:pullingPercent]; 80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)]; 81 | if (self.state != MJRefreshStateIdle || images.count == 0) return; 82 | // 停止动画 83 | [self.gifView stopAnimating]; 84 | // 设置当前需要显示的图片 85 | NSUInteger index = images.count * pullingPercent; 86 | if (index >= images.count) index = images.count - 1; 87 | self.gifView.image = images[index]; 88 | } 89 | 90 | - (void)placeSubviews 91 | { 92 | [super placeSubviews]; 93 | 94 | if (self.gifView.constraints.count) return; 95 | 96 | self.gifView.frame = self.bounds; 97 | if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) { 98 | self.gifView.contentMode = UIViewContentModeCenter; 99 | } else { 100 | self.gifView.contentMode = UIViewContentModeRight; 101 | 102 | CGFloat stateWidth = self.stateLabel.mj_textWith; 103 | CGFloat timeWidth = 0.0; 104 | if (!self.lastUpdatedTimeLabel.hidden) { 105 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith; 106 | } 107 | CGFloat textWidth = MAX(stateWidth, timeWidth); 108 | self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset; 109 | } 110 | } 111 | 112 | - (void)setState:(MJRefreshState)state 113 | { 114 | MJRefreshCheckState 115 | 116 | // 根据状态做事情 117 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) { 118 | NSArray *images = self.stateImages[@(state)]; 119 | if (images.count == 0) return; 120 | 121 | [self.gifView stopAnimating]; 122 | if (images.count == 1) { // 单张图片 123 | self.gifView.image = [images lastObject]; 124 | } else { // 多张图片 125 | self.gifView.animationImages = images; 126 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue]; 127 | [self.gifView startAnimating]; 128 | } 129 | } else if (state == MJRefreshStateIdle) { 130 | [self.gifView stopAnimating]; 131 | } 132 | } 133 | @end 134 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshNormalHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshNormalHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshNormalHeader : MJRefreshStateHeader 12 | @property (weak, nonatomic, readonly) UIImageView *arrowView; 13 | /** 菊花的样式 */ 14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; 15 | @end 16 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshNormalHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshNormalHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshNormalHeader.h" 10 | #import "NSBundle+MJRefresh.h" 11 | 12 | @interface MJRefreshNormalHeader() 13 | { 14 | __unsafe_unretained UIImageView *_arrowView; 15 | } 16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView; 17 | @end 18 | 19 | @implementation MJRefreshNormalHeader 20 | #pragma mark - 懒加载子控件 21 | - (UIImageView *)arrowView 22 | { 23 | if (!_arrowView) { 24 | UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]]; 25 | [self addSubview:_arrowView = arrowView]; 26 | } 27 | return _arrowView; 28 | } 29 | 30 | - (UIActivityIndicatorView *)loadingView 31 | { 32 | if (!_loadingView) { 33 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle]; 34 | loadingView.hidesWhenStopped = YES; 35 | [self addSubview:_loadingView = loadingView]; 36 | } 37 | return _loadingView; 38 | } 39 | 40 | #pragma mark - 公共方法 41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle 42 | { 43 | _activityIndicatorViewStyle = activityIndicatorViewStyle; 44 | 45 | self.loadingView = nil; 46 | [self setNeedsLayout]; 47 | } 48 | 49 | #pragma mark - 重写父类的方法 50 | - (void)prepare 51 | { 52 | [super prepare]; 53 | 54 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 55 | } 56 | 57 | - (void)placeSubviews 58 | { 59 | [super placeSubviews]; 60 | 61 | // 箭头的中心点 62 | CGFloat arrowCenterX = self.mj_w * 0.5; 63 | if (!self.stateLabel.hidden) { 64 | CGFloat stateWidth = self.stateLabel.mj_textWith; 65 | CGFloat timeWidth = 0.0; 66 | if (!self.lastUpdatedTimeLabel.hidden) { 67 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith; 68 | } 69 | CGFloat textWidth = MAX(stateWidth, timeWidth); 70 | arrowCenterX -= textWidth / 2 + self.labelLeftInset; 71 | } 72 | CGFloat arrowCenterY = self.mj_h * 0.5; 73 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY); 74 | 75 | // 箭头 76 | if (self.arrowView.constraints.count == 0) { 77 | self.arrowView.mj_size = self.arrowView.image.size; 78 | self.arrowView.center = arrowCenter; 79 | } 80 | 81 | // 圈圈 82 | if (self.loadingView.constraints.count == 0) { 83 | self.loadingView.center = arrowCenter; 84 | } 85 | 86 | self.arrowView.tintColor = self.stateLabel.textColor; 87 | } 88 | 89 | - (void)setState:(MJRefreshState)state 90 | { 91 | MJRefreshCheckState 92 | 93 | // 根据状态做事情 94 | if (state == MJRefreshStateIdle) { 95 | if (oldState == MJRefreshStateRefreshing) { 96 | self.arrowView.transform = CGAffineTransformIdentity; 97 | 98 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{ 99 | self.loadingView.alpha = 0.0; 100 | } completion:^(BOOL finished) { 101 | // 如果执行完动画发现不是idle状态,就直接返回,进入其他状态 102 | if (self.state != MJRefreshStateIdle) return; 103 | 104 | self.loadingView.alpha = 1.0; 105 | [self.loadingView stopAnimating]; 106 | self.arrowView.hidden = NO; 107 | }]; 108 | } else { 109 | [self.loadingView stopAnimating]; 110 | self.arrowView.hidden = NO; 111 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 112 | self.arrowView.transform = CGAffineTransformIdentity; 113 | }]; 114 | } 115 | } else if (state == MJRefreshStatePulling) { 116 | [self.loadingView stopAnimating]; 117 | self.arrowView.hidden = NO; 118 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{ 119 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI); 120 | }]; 121 | } else if (state == MJRefreshStateRefreshing) { 122 | self.loadingView.alpha = 1.0; // 防止refreshing -> idle的动画完毕动作没有被执行 123 | [self.loadingView startAnimating]; 124 | self.arrowView.hidden = YES; 125 | } 126 | } 127 | @end 128 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshStateHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshStateHeader.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshHeader.h" 10 | 11 | @interface MJRefreshStateHeader : MJRefreshHeader 12 | #pragma mark - 刷新时间相关 13 | /** 利用这个block来决定显示的更新时间文字 */ 14 | @property (copy, nonatomic) NSString *(^lastUpdatedTimeText)(NSDate *lastUpdatedTime); 15 | /** 显示上一次刷新时间的label */ 16 | @property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel; 17 | 18 | #pragma mark - 状态相关 19 | /** 文字距离圈圈、箭头的距离 */ 20 | @property (assign, nonatomic) CGFloat labelLeftInset; 21 | /** 显示刷新状态的label */ 22 | @property (weak, nonatomic, readonly) UILabel *stateLabel; 23 | /** 设置state状态下的文字 */ 24 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state; 25 | @end 26 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/Custom/Header/MJRefreshStateHeader.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJRefreshStateHeader.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 15/4/24. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJRefreshStateHeader.h" 10 | 11 | @interface MJRefreshStateHeader() 12 | { 13 | /** 显示上一次刷新时间的label */ 14 | __unsafe_unretained UILabel *_lastUpdatedTimeLabel; 15 | /** 显示刷新状态的label */ 16 | __unsafe_unretained UILabel *_stateLabel; 17 | } 18 | /** 所有状态对应的文字 */ 19 | @property (strong, nonatomic) NSMutableDictionary *stateTitles; 20 | @end 21 | 22 | @implementation MJRefreshStateHeader 23 | #pragma mark - 懒加载 24 | - (NSMutableDictionary *)stateTitles 25 | { 26 | if (!_stateTitles) { 27 | self.stateTitles = [NSMutableDictionary dictionary]; 28 | } 29 | return _stateTitles; 30 | } 31 | 32 | - (UILabel *)stateLabel 33 | { 34 | if (!_stateLabel) { 35 | [self addSubview:_stateLabel = [UILabel mj_label]]; 36 | } 37 | return _stateLabel; 38 | } 39 | 40 | - (UILabel *)lastUpdatedTimeLabel 41 | { 42 | if (!_lastUpdatedTimeLabel) { 43 | [self addSubview:_lastUpdatedTimeLabel = [UILabel mj_label]]; 44 | } 45 | return _lastUpdatedTimeLabel; 46 | } 47 | 48 | #pragma mark - 公共方法 49 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state 50 | { 51 | if (title == nil) return; 52 | self.stateTitles[@(state)] = title; 53 | self.stateLabel.text = self.stateTitles[@(self.state)]; 54 | } 55 | 56 | #pragma mark - 日历获取在9.x之后的系统使用currentCalendar会出异常。在8.0之后使用系统新API。 57 | - (NSCalendar *)currentCalendar { 58 | if ([NSCalendar respondsToSelector:@selector(calendarWithIdentifier:)]) { 59 | return [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; 60 | } 61 | return [NSCalendar currentCalendar]; 62 | } 63 | 64 | #pragma mark key的处理 65 | - (void)setLastUpdatedTimeKey:(NSString *)lastUpdatedTimeKey 66 | { 67 | [super setLastUpdatedTimeKey:lastUpdatedTimeKey]; 68 | 69 | // 如果label隐藏了,就不用再处理 70 | if (self.lastUpdatedTimeLabel.hidden) return; 71 | 72 | NSDate *lastUpdatedTime = [[NSUserDefaults standardUserDefaults] objectForKey:lastUpdatedTimeKey]; 73 | 74 | // 如果有block 75 | if (self.lastUpdatedTimeText) { 76 | self.lastUpdatedTimeLabel.text = self.lastUpdatedTimeText(lastUpdatedTime); 77 | return; 78 | } 79 | 80 | if (lastUpdatedTime) { 81 | // 1.获得年月日 82 | NSCalendar *calendar = [self currentCalendar]; 83 | NSUInteger unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour |NSCalendarUnitMinute; 84 | NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:lastUpdatedTime]; 85 | NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]]; 86 | 87 | // 2.格式化日期 88 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 89 | BOOL isToday = NO; 90 | if ([cmp1 day] == [cmp2 day]) { // 今天 91 | formatter.dateFormat = @" HH:mm"; 92 | isToday = YES; 93 | } else if ([cmp1 year] == [cmp2 year]) { // 今年 94 | formatter.dateFormat = @"MM-dd HH:mm"; 95 | } else { 96 | formatter.dateFormat = @"yyyy-MM-dd HH:mm"; 97 | } 98 | NSString *time = [formatter stringFromDate:lastUpdatedTime]; 99 | 100 | // 3.显示日期 101 | self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@%@", 102 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], 103 | isToday ? [NSBundle mj_localizedStringForKey:MJRefreshHeaderDateTodayText] : @"", 104 | time]; 105 | } else { 106 | self.lastUpdatedTimeLabel.text = [NSString stringWithFormat:@"%@%@", 107 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderLastTimeText], 108 | [NSBundle mj_localizedStringForKey:MJRefreshHeaderNoneLastDateText]]; 109 | } 110 | } 111 | 112 | #pragma mark - 覆盖父类的方法 113 | - (void)prepare 114 | { 115 | [super prepare]; 116 | 117 | // 初始化间距 118 | self.labelLeftInset = MJRefreshLabelLeftInset; 119 | 120 | // 初始化文字 121 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderIdleText] forState:MJRefreshStateIdle]; 122 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderPullingText] forState:MJRefreshStatePulling]; 123 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshHeaderRefreshingText] forState:MJRefreshStateRefreshing]; 124 | } 125 | 126 | - (void)placeSubviews 127 | { 128 | [super placeSubviews]; 129 | 130 | if (self.stateLabel.hidden) return; 131 | 132 | BOOL noConstrainsOnStatusLabel = self.stateLabel.constraints.count == 0; 133 | 134 | if (self.lastUpdatedTimeLabel.hidden) { 135 | // 状态 136 | if (noConstrainsOnStatusLabel) self.stateLabel.frame = self.bounds; 137 | } else { 138 | CGFloat stateLabelH = self.mj_h * 0.5; 139 | // 状态 140 | if (noConstrainsOnStatusLabel) { 141 | self.stateLabel.mj_x = 0; 142 | self.stateLabel.mj_y = 0; 143 | self.stateLabel.mj_w = self.mj_w; 144 | self.stateLabel.mj_h = stateLabelH; 145 | } 146 | 147 | // 更新时间 148 | if (self.lastUpdatedTimeLabel.constraints.count == 0) { 149 | self.lastUpdatedTimeLabel.mj_x = 0; 150 | self.lastUpdatedTimeLabel.mj_y = stateLabelH; 151 | self.lastUpdatedTimeLabel.mj_w = self.mj_w; 152 | self.lastUpdatedTimeLabel.mj_h = self.mj_h - self.lastUpdatedTimeLabel.mj_y; 153 | } 154 | } 155 | } 156 | 157 | - (void)setState:(MJRefreshState)state 158 | { 159 | MJRefreshCheckState 160 | 161 | // 设置状态文字 162 | self.stateLabel.text = self.stateTitles[@(state)]; 163 | 164 | // 重新设置key(重新显示时间) 165 | self.lastUpdatedTimeKey = self.lastUpdatedTimeKey; 166 | } 167 | @end 168 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/arrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanyx1992/XYTableViewNoDataView/e7de96f22c30959dae5b2146f19cb9f6973af7a2/XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/arrow@2x.png -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanyx1992/XYTableViewNoDataView/e7de96f22c30959dae5b2146f19cb9f6973af7a2/XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanyx1992/XYTableViewNoDataView/e7de96f22c30959dae5b2146f19cb9f6973af7a2/XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | "MJRefreshHeaderIdleText" = "下拉可以刷新"; 2 | "MJRefreshHeaderPullingText" = "鬆開立即刷新"; 3 | "MJRefreshHeaderRefreshingText" = "正在刷新數據中..."; 4 | 5 | "MJRefreshAutoFooterIdleText" = "點擊或上拉加載更多"; 6 | "MJRefreshAutoFooterRefreshingText" = "正在加載更多的數據..."; 7 | "MJRefreshAutoFooterNoMoreDataText" = "已經全部加載完畢"; 8 | 9 | "MJRefreshBackFooterIdleText" = "上拉可以加載更多"; 10 | "MJRefreshBackFooterPullingText" = "鬆開立即加載更多"; 11 | "MJRefreshBackFooterRefreshingText" = "正在加載更多的數據..."; 12 | "MJRefreshBackFooterNoMoreDataText" = "已經全部加載完畢"; 13 | 14 | "MJRefreshHeaderLastTimeText" = "最後更新:"; 15 | "MJRefreshHeaderDateTodayText" = "今天"; 16 | "MJRefreshHeaderNoneLastDateText" = "無記錄"; 17 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | 4 | #import "UIScrollView+MJRefresh.h" 5 | #import "UIScrollView+MJExtension.h" 6 | #import "UIView+MJExtension.h" 7 | 8 | #import "MJRefreshNormalHeader.h" 9 | #import "MJRefreshGifHeader.h" 10 | 11 | #import "MJRefreshBackNormalFooter.h" 12 | #import "MJRefreshBackGifFooter.h" 13 | #import "MJRefreshAutoNormalFooter.h" 14 | #import "MJRefreshAutoGifFooter.h" -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefreshConst.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | #import 4 | #import 5 | 6 | // 弱引用 7 | #define MJWeakSelf __weak typeof(self) weakSelf = self; 8 | 9 | // 日志输出 10 | #ifdef DEBUG 11 | #define MJRefreshLog(...) NSLog(__VA_ARGS__) 12 | #else 13 | #define MJRefreshLog(...) 14 | #endif 15 | 16 | // 过期提醒 17 | #define MJRefreshDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead) 18 | 19 | // 运行时objc_msgSend 20 | #define MJRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__) 21 | #define MJRefreshMsgTarget(target) (__bridge void *)(target) 22 | 23 | // RGB颜色 24 | #define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0] 25 | 26 | // 文字颜色 27 | #define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90) 28 | 29 | // 字体大小 30 | #define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14] 31 | 32 | // 常量 33 | UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset; 34 | UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight; 35 | UIKIT_EXTERN const CGFloat MJRefreshFooterHeight; 36 | UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration; 37 | UIKIT_EXTERN const CGFloat MJRefreshSlowAnimationDuration; 38 | 39 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentOffset; 40 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentSize; 41 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentInset; 42 | UIKIT_EXTERN NSString *const MJRefreshKeyPathPanState; 43 | 44 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastUpdatedTimeKey; 45 | 46 | UIKIT_EXTERN NSString *const MJRefreshHeaderIdleText; 47 | UIKIT_EXTERN NSString *const MJRefreshHeaderPullingText; 48 | UIKIT_EXTERN NSString *const MJRefreshHeaderRefreshingText; 49 | 50 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterIdleText; 51 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterRefreshingText; 52 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterNoMoreDataText; 53 | 54 | UIKIT_EXTERN NSString *const MJRefreshBackFooterIdleText; 55 | UIKIT_EXTERN NSString *const MJRefreshBackFooterPullingText; 56 | UIKIT_EXTERN NSString *const MJRefreshBackFooterRefreshingText; 57 | UIKIT_EXTERN NSString *const MJRefreshBackFooterNoMoreDataText; 58 | 59 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastTimeText; 60 | UIKIT_EXTERN NSString *const MJRefreshHeaderDateTodayText; 61 | UIKIT_EXTERN NSString *const MJRefreshHeaderNoneLastDateText; 62 | 63 | // 状态检查 64 | #define MJRefreshCheckState \ 65 | MJRefreshState oldState = self.state; \ 66 | if (state == oldState) return; \ 67 | [super setState:state]; 68 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/MJRefreshConst.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | #import 4 | 5 | const CGFloat MJRefreshLabelLeftInset = 25; 6 | const CGFloat MJRefreshHeaderHeight = 54.0; 7 | const CGFloat MJRefreshFooterHeight = 44.0; 8 | const CGFloat MJRefreshFastAnimationDuration = 0.25; 9 | const CGFloat MJRefreshSlowAnimationDuration = 0.4; 10 | 11 | NSString *const MJRefreshKeyPathContentOffset = @"contentOffset"; 12 | NSString *const MJRefreshKeyPathContentInset = @"contentInset"; 13 | NSString *const MJRefreshKeyPathContentSize = @"contentSize"; 14 | NSString *const MJRefreshKeyPathPanState = @"state"; 15 | 16 | NSString *const MJRefreshHeaderLastUpdatedTimeKey = @"MJRefreshHeaderLastUpdatedTimeKey"; 17 | 18 | NSString *const MJRefreshHeaderIdleText = @"MJRefreshHeaderIdleText"; 19 | NSString *const MJRefreshHeaderPullingText = @"MJRefreshHeaderPullingText"; 20 | NSString *const MJRefreshHeaderRefreshingText = @"MJRefreshHeaderRefreshingText"; 21 | 22 | NSString *const MJRefreshAutoFooterIdleText = @"MJRefreshAutoFooterIdleText"; 23 | NSString *const MJRefreshAutoFooterRefreshingText = @"MJRefreshAutoFooterRefreshingText"; 24 | NSString *const MJRefreshAutoFooterNoMoreDataText = @"MJRefreshAutoFooterNoMoreDataText"; 25 | 26 | NSString *const MJRefreshBackFooterIdleText = @"MJRefreshBackFooterIdleText"; 27 | NSString *const MJRefreshBackFooterPullingText = @"MJRefreshBackFooterPullingText"; 28 | NSString *const MJRefreshBackFooterRefreshingText = @"MJRefreshBackFooterRefreshingText"; 29 | NSString *const MJRefreshBackFooterNoMoreDataText = @"MJRefreshBackFooterNoMoreDataText"; 30 | 31 | NSString *const MJRefreshHeaderLastTimeText = @"MJRefreshHeaderLastTimeText"; 32 | NSString *const MJRefreshHeaderDateTodayText = @"MJRefreshHeaderDateTodayText"; 33 | NSString *const MJRefreshHeaderNoneLastDateText = @"MJRefreshHeaderNoneLastDateText"; -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/NSBundle+MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSBundle+MJRefresh.h 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 16/6/13. 6 | // Copyright © 2016年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSBundle (MJRefresh) 12 | + (instancetype)mj_refreshBundle; 13 | + (UIImage *)mj_arrowImage; 14 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value; 15 | + (NSString *)mj_localizedStringForKey:(NSString *)key; 16 | @end 17 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/NSBundle+MJRefresh.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSBundle+MJRefresh.m 3 | // MJRefreshExample 4 | // 5 | // Created by MJ Lee on 16/6/13. 6 | // Copyright © 2016年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "NSBundle+MJRefresh.h" 10 | #import "MJRefreshComponent.h" 11 | 12 | @implementation NSBundle (MJRefresh) 13 | + (instancetype)mj_refreshBundle 14 | { 15 | static NSBundle *refreshBundle = nil; 16 | if (refreshBundle == nil) { 17 | // 这里不使用mainBundle是为了适配pod 1.x和0.x 18 | refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]]; 19 | } 20 | return refreshBundle; 21 | } 22 | 23 | + (UIImage *)mj_arrowImage 24 | { 25 | static UIImage *arrowImage = nil; 26 | if (arrowImage == nil) { 27 | arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 28 | } 29 | return arrowImage; 30 | } 31 | 32 | + (NSString *)mj_localizedStringForKey:(NSString *)key 33 | { 34 | return [self mj_localizedStringForKey:key value:nil]; 35 | } 36 | 37 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value 38 | { 39 | static NSBundle *bundle = nil; 40 | if (bundle == nil) { 41 | // (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理 42 | NSString *language = [NSLocale preferredLanguages].firstObject; 43 | if ([language hasPrefix:@"en"]) { 44 | language = @"en"; 45 | } else if ([language hasPrefix:@"zh"]) { 46 | if ([language rangeOfString:@"Hans"].location != NSNotFound) { 47 | language = @"zh-Hans"; // 简体中文 48 | } else { // zh-Hant\zh-HK\zh-TW 49 | language = @"zh-Hant"; // 繁體中文 50 | } 51 | } else { 52 | language = @"en"; 53 | } 54 | 55 | // 从MJRefresh.bundle中查找资源 56 | bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]]; 57 | } 58 | value = [bundle localizedStringForKey:key value:value table:nil]; 59 | return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil]; 60 | } 61 | @end 62 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/UIScrollView+MJExtension.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // UIScrollView+Extension.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import 11 | 12 | @interface UIScrollView (MJExtension) 13 | @property (readonly, nonatomic) UIEdgeInsets mj_inset; 14 | 15 | @property (assign, nonatomic) CGFloat mj_insetT; 16 | @property (assign, nonatomic) CGFloat mj_insetB; 17 | @property (assign, nonatomic) CGFloat mj_insetL; 18 | @property (assign, nonatomic) CGFloat mj_insetR; 19 | 20 | @property (assign, nonatomic) CGFloat mj_offsetX; 21 | @property (assign, nonatomic) CGFloat mj_offsetY; 22 | 23 | @property (assign, nonatomic) CGFloat mj_contentW; 24 | @property (assign, nonatomic) CGFloat mj_contentH; 25 | @end 26 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/UIScrollView+MJExtension.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // UIScrollView+Extension.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIScrollView+MJExtension.h" 11 | #import 12 | 13 | #define SYSTEM_VERSION_GREATER_NOT_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 14 | 15 | #pragma clang diagnostic push 16 | #pragma clang diagnostic ignored "-Wunguarded-availability-new" 17 | 18 | @implementation UIScrollView (MJExtension) 19 | 20 | - (UIEdgeInsets)mj_inset 21 | { 22 | #ifdef __IPHONE_11_0 23 | if (SYSTEM_VERSION_GREATER_NOT_LESS_THAN(@"11.0")) { 24 | return self.adjustedContentInset; 25 | } 26 | #endif 27 | return self.contentInset; 28 | } 29 | 30 | - (void)setMj_insetT:(CGFloat)mj_insetT 31 | { 32 | UIEdgeInsets inset = self.contentInset; 33 | inset.top = mj_insetT; 34 | #ifdef __IPHONE_11_0 35 | if (SYSTEM_VERSION_GREATER_NOT_LESS_THAN(@"11.0")) { 36 | inset.top -= (self.adjustedContentInset.top - self.contentInset.top); 37 | } 38 | #endif 39 | self.contentInset = inset; 40 | } 41 | 42 | - (CGFloat)mj_insetT 43 | { 44 | return self.mj_inset.top; 45 | } 46 | 47 | - (void)setMj_insetB:(CGFloat)mj_insetB 48 | { 49 | UIEdgeInsets inset = self.contentInset; 50 | inset.bottom = mj_insetB; 51 | #ifdef __IPHONE_11_0 52 | if (SYSTEM_VERSION_GREATER_NOT_LESS_THAN(@"11.0")) { 53 | inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom); 54 | } 55 | #endif 56 | self.contentInset = inset; 57 | } 58 | 59 | - (CGFloat)mj_insetB 60 | { 61 | return self.mj_inset.bottom; 62 | } 63 | 64 | - (void)setMj_insetL:(CGFloat)mj_insetL 65 | { 66 | UIEdgeInsets inset = self.contentInset; 67 | inset.left = mj_insetL; 68 | #ifdef __IPHONE_11_0 69 | if (SYSTEM_VERSION_GREATER_NOT_LESS_THAN(@"11.0")) { 70 | inset.left -= (self.adjustedContentInset.left - self.contentInset.left); 71 | } 72 | #endif 73 | self.contentInset = inset; 74 | } 75 | 76 | - (CGFloat)mj_insetL 77 | { 78 | return self.mj_inset.left; 79 | } 80 | 81 | - (void)setMj_insetR:(CGFloat)mj_insetR 82 | { 83 | UIEdgeInsets inset = self.contentInset; 84 | inset.right = mj_insetR; 85 | #ifdef __IPHONE_11_0 86 | if (SYSTEM_VERSION_GREATER_NOT_LESS_THAN(@"11.0")) { 87 | inset.right -= (self.adjustedContentInset.right - self.contentInset.right); 88 | } 89 | #endif 90 | self.contentInset = inset; 91 | } 92 | 93 | - (CGFloat)mj_insetR 94 | { 95 | return self.mj_inset.right; 96 | } 97 | 98 | - (void)setMj_offsetX:(CGFloat)mj_offsetX 99 | { 100 | CGPoint offset = self.contentOffset; 101 | offset.x = mj_offsetX; 102 | self.contentOffset = offset; 103 | } 104 | 105 | - (CGFloat)mj_offsetX 106 | { 107 | return self.contentOffset.x; 108 | } 109 | 110 | - (void)setMj_offsetY:(CGFloat)mj_offsetY 111 | { 112 | CGPoint offset = self.contentOffset; 113 | offset.y = mj_offsetY; 114 | self.contentOffset = offset; 115 | } 116 | 117 | - (CGFloat)mj_offsetY 118 | { 119 | return self.contentOffset.y; 120 | } 121 | 122 | - (void)setMj_contentW:(CGFloat)mj_contentW 123 | { 124 | CGSize size = self.contentSize; 125 | size.width = mj_contentW; 126 | self.contentSize = size; 127 | } 128 | 129 | - (CGFloat)mj_contentW 130 | { 131 | return self.contentSize.width; 132 | } 133 | 134 | - (void)setMj_contentH:(CGFloat)mj_contentH 135 | { 136 | CGSize size = self.contentSize; 137 | size.height = mj_contentH; 138 | self.contentSize = size; 139 | } 140 | 141 | - (CGFloat)mj_contentH 142 | { 143 | return self.contentSize.height; 144 | } 145 | @end 146 | #pragma clang diagnostic pop 147 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/UIScrollView+MJRefresh.h: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // UIScrollView+MJRefresh.h 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 给ScrollView增加下拉刷新、上拉刷新的功能 9 | 10 | #import 11 | #import "MJRefreshConst.h" 12 | 13 | @class MJRefreshHeader, MJRefreshFooter; 14 | 15 | @interface UIScrollView (MJRefresh) 16 | /** 下拉刷新控件 */ 17 | @property (strong, nonatomic) MJRefreshHeader *mj_header; 18 | @property (strong, nonatomic) MJRefreshHeader *header MJRefreshDeprecated("使用mj_header"); 19 | /** 上拉刷新控件 */ 20 | @property (strong, nonatomic) MJRefreshFooter *mj_footer; 21 | @property (strong, nonatomic) MJRefreshFooter *footer MJRefreshDeprecated("使用mj_footer"); 22 | 23 | #pragma mark - other 24 | - (NSInteger)mj_totalDataCount; 25 | @property (copy, nonatomic) void (^mj_reloadDataBlock)(NSInteger totalDataCount); 26 | @end 27 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/UIScrollView+MJRefresh.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // UIScrollView+MJRefresh.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 15/3/4. 7 | // Copyright (c) 2015年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIScrollView+MJRefresh.h" 11 | #import "MJRefreshHeader.h" 12 | #import "MJRefreshFooter.h" 13 | #import 14 | 15 | @implementation NSObject (MJRefresh) 16 | 17 | + (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2 18 | { 19 | method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2)); 20 | } 21 | 22 | + (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2 23 | { 24 | method_exchangeImplementations(class_getClassMethod(self, method1), class_getClassMethod(self, method2)); 25 | } 26 | 27 | @end 28 | 29 | @implementation UIScrollView (MJRefresh) 30 | 31 | #pragma mark - header 32 | static const char MJRefreshHeaderKey = '\0'; 33 | - (void)setMj_header:(MJRefreshHeader *)mj_header 34 | { 35 | if (mj_header != self.mj_header) { 36 | // 删除旧的,添加新的 37 | [self.mj_header removeFromSuperview]; 38 | [self insertSubview:mj_header atIndex:0]; 39 | 40 | // 存储新的 41 | [self willChangeValueForKey:@"mj_header"]; // KVO 42 | objc_setAssociatedObject(self, &MJRefreshHeaderKey, 43 | mj_header, OBJC_ASSOCIATION_ASSIGN); 44 | [self didChangeValueForKey:@"mj_header"]; // KVO 45 | } 46 | } 47 | 48 | - (MJRefreshHeader *)mj_header 49 | { 50 | return objc_getAssociatedObject(self, &MJRefreshHeaderKey); 51 | } 52 | 53 | #pragma mark - footer 54 | static const char MJRefreshFooterKey = '\0'; 55 | - (void)setMj_footer:(MJRefreshFooter *)mj_footer 56 | { 57 | if (mj_footer != self.mj_footer) { 58 | // 删除旧的,添加新的 59 | [self.mj_footer removeFromSuperview]; 60 | [self insertSubview:mj_footer atIndex:0]; 61 | 62 | // 存储新的 63 | [self willChangeValueForKey:@"mj_footer"]; // KVO 64 | objc_setAssociatedObject(self, &MJRefreshFooterKey, 65 | mj_footer, OBJC_ASSOCIATION_ASSIGN); 66 | [self didChangeValueForKey:@"mj_footer"]; // KVO 67 | } 68 | } 69 | 70 | - (MJRefreshFooter *)mj_footer 71 | { 72 | return objc_getAssociatedObject(self, &MJRefreshFooterKey); 73 | } 74 | 75 | #pragma mark - 过期 76 | - (void)setFooter:(MJRefreshFooter *)footer 77 | { 78 | self.mj_footer = footer; 79 | } 80 | 81 | - (MJRefreshFooter *)footer 82 | { 83 | return self.mj_footer; 84 | } 85 | 86 | - (void)setHeader:(MJRefreshHeader *)header 87 | { 88 | self.mj_header = header; 89 | } 90 | 91 | - (MJRefreshHeader *)header 92 | { 93 | return self.mj_header; 94 | } 95 | 96 | #pragma mark - other 97 | - (NSInteger)mj_totalDataCount 98 | { 99 | NSInteger totalCount = 0; 100 | if ([self isKindOfClass:[UITableView class]]) { 101 | UITableView *tableView = (UITableView *)self; 102 | 103 | for (NSInteger section = 0; section 11 | 12 | @interface UIView (MJExtension) 13 | @property (assign, nonatomic) CGFloat mj_x; 14 | @property (assign, nonatomic) CGFloat mj_y; 15 | @property (assign, nonatomic) CGFloat mj_w; 16 | @property (assign, nonatomic) CGFloat mj_h; 17 | @property (assign, nonatomic) CGSize mj_size; 18 | @property (assign, nonatomic) CGPoint mj_origin; 19 | @end 20 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/MJRefresh/UIView+MJExtension.m: -------------------------------------------------------------------------------- 1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh 2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000 3 | // UIView+Extension.m 4 | // MJRefreshExample 5 | // 6 | // Created by MJ Lee on 14-5-28. 7 | // Copyright (c) 2014年 小码哥. All rights reserved. 8 | // 9 | 10 | #import "UIView+MJExtension.h" 11 | 12 | @implementation UIView (MJExtension) 13 | - (void)setMj_x:(CGFloat)mj_x 14 | { 15 | CGRect frame = self.frame; 16 | frame.origin.x = mj_x; 17 | self.frame = frame; 18 | } 19 | 20 | - (CGFloat)mj_x 21 | { 22 | return self.frame.origin.x; 23 | } 24 | 25 | - (void)setMj_y:(CGFloat)mj_y 26 | { 27 | CGRect frame = self.frame; 28 | frame.origin.y = mj_y; 29 | self.frame = frame; 30 | } 31 | 32 | - (CGFloat)mj_y 33 | { 34 | return self.frame.origin.y; 35 | } 36 | 37 | - (void)setMj_w:(CGFloat)mj_w 38 | { 39 | CGRect frame = self.frame; 40 | frame.size.width = mj_w; 41 | self.frame = frame; 42 | } 43 | 44 | - (CGFloat)mj_w 45 | { 46 | return self.frame.size.width; 47 | } 48 | 49 | - (void)setMj_h:(CGFloat)mj_h 50 | { 51 | CGRect frame = self.frame; 52 | frame.size.height = mj_h; 53 | self.frame = frame; 54 | } 55 | 56 | - (CGFloat)mj_h 57 | { 58 | return self.frame.size.height; 59 | } 60 | 61 | - (void)setMj_size:(CGSize)mj_size 62 | { 63 | CGRect frame = self.frame; 64 | frame.size = mj_size; 65 | self.frame = frame; 66 | } 67 | 68 | - (CGSize)mj_size 69 | { 70 | return self.frame.size; 71 | } 72 | 73 | - (void)setMj_origin:(CGPoint)mj_origin 74 | { 75 | CGRect frame = self.frame; 76 | frame.origin = mj_origin; 77 | self.frame = frame; 78 | } 79 | 80 | - (CGPoint)mj_origin 81 | { 82 | return self.frame.origin; 83 | } 84 | @end 85 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "MJRefresh.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (weak, nonatomic) IBOutlet UITableView *tableView; 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | self.tableView.delegate = self; 24 | self.tableView.dataSource = self; 25 | self.tableView.tableFooterView = [UIView new]; 26 | 27 | __weak typeof(self) weakSelf = self; 28 | self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ 29 | [weakSelf loadData]; 30 | }]; 31 | } 32 | 33 | - (void)loadData { 34 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 35 | [self.tableView.mj_header endRefreshing]; 36 | [self.tableView reloadData]; 37 | }); 38 | } 39 | 40 | #pragma mark - UITableViewDelegate & UITableViewDataSource 41 | 42 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 43 | return 0; 44 | } 45 | 46 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 47 | return [[UITableViewCell alloc] init]; 48 | } 49 | 50 | #pragma mark - TableView 占位图 51 | 52 | - (UIImage *)xy_noDataViewImage { 53 | return [UIImage imageNamed:@"note_list_no_data"]; 54 | } 55 | 56 | - (NSString *)xy_noDataViewMessage { 57 | return @"都用起来吧, 起飞~"; 58 | } 59 | 60 | - (UIColor *)xy_noDataViewMessageColor { 61 | return [UIColor blackColor]; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /XYTableViewNoDataViewDemo/XYTableViewNoDataViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // XYTableViewNoDataViewDemo 4 | // 5 | // Created by 韩元旭 on 2017/7/19. 6 | // Copyright © 2017年 韩元旭. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------