diff --git a/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.h b/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.h index dab95da..05f3cd9 100644 --- a/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.h +++ b/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.h @@ -68,17 +68,24 @@ - (void)endPullDownRefreshing; /** - * 当上啦加载数据完成后,你也得调用该方法哦!然后你可能会问,那我要怎么判断是下拉还是上啦啊?requestCurrentPage看这个变量,会跟着变化哦! + * 当上拉加载数据完成后,你也得调用该方法哦!然后你可能会问,那我要怎么判断是下拉还是上啦啊?requestCurrentPage看这个变量,会跟着变化哦! */ - (void)endLoadMoreRefreshing; /** - * 当上啦加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! + * 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! * * @param message 提示用户的信息 */ - (void)endMoreOverWithMessage:(NSString *)message; +/** + * 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! + * + * @param messageTipsView 提示用户的视图 + */ +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView; + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.m b/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.m index 6c00748..65ed14e 100644 --- a/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.m +++ b/RefreshControl/Controllers/CustomTableViewController/XHPullRefreshTableViewController.m @@ -32,6 +32,10 @@ - (void)endMoreOverWithMessage:(NSString *)message { [self.refreshControl endMoreOverWithMessage:message]; } +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView { + [self.refreshControl endMoreOverWithMessageTipsView:messageTipsView]; +} + - (void)resetLoadMoreStatue:(BOOL)noMoreDataForLoaded { [self.refreshControl resetLoadMoreStatue:noMoreDataForLoaded]; } diff --git a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.h b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.h index 49b9e83..a648f94 100644 --- a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.h +++ b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.h @@ -15,22 +15,10 @@ * 大量数据的数据源 */ @property (nonatomic, strong) NSMutableArray *dataSource; + /** * 加载本地或者网络数据源 */ - (void)loadDataSource; -// -///** -// * 去除iOS7新的功能api,tableView的分割线变成iOS6正常的样式 -// */ -//- (void)configuraTableViewNormalSeparatorInset; - -///** -// * 配置tableView右侧的index title 背景颜色,因为在iOS7有白色底色,iOS6没有 -// * -// * @param tableView 目标tableView -// */ -//- (void)configuraSectionIndexBackgroundColorWithTableView:(UITableView *)tableView; - @end diff --git a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.m b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.m index 4e7ec03..f14ca29 100644 --- a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.m +++ b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.m @@ -21,10 +21,12 @@ - (void)loadDataSource { // in subClass } -#pragma mark - UITableView DataSource +#pragma mark - UICollectionView DataSource + - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } + - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataSource.count; } diff --git a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.h b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.h index 8906545..92045c5 100644 --- a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.h +++ b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.h @@ -69,6 +69,13 @@ */ - (void)endMoreOverWithMessage:(NSString *)message; +/** + * 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! + * + * @param messageTipsView 提示用户的视图 + */ +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView; + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.m b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.m index 1226757..74f9dac 100644 --- a/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.m +++ b/RefreshControl/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.m @@ -32,6 +32,10 @@ - (void)endMoreOverWithMessage:(NSString *)message { [self.customRefreshControl endMoreOverWithMessage:message]; } +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView { + [self.customRefreshControl endMoreOverWithMessageTipsView:messageTipsView]; +} + - (void)resetLoadMoreStatue:(BOOL)noMoreDataForLoaded { [self.customRefreshControl resetLoadMoreStatue:noMoreDataForLoaded]; } diff --git a/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.h b/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.h index c43dce1..42bc175 100644 --- a/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.h +++ b/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.h @@ -74,6 +74,13 @@ */ - (void)endMoreOverWithMessage:(NSString *)message; +/** + * 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! + * + * @param messageTipsView 提示用户的视图 + */ +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView; + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.m b/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.m index 63f4cb9..dc2d698 100644 --- a/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.m +++ b/RefreshControl/Controllers/SystemTableViewController/XHSysatemRefreshTableViewController.m @@ -32,6 +32,10 @@ - (void)endMoreOverWithMessage:(NSString *)message { [self.customRefreshControl endMoreOverWithMessage:message]; } +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView { + [self.customRefreshControl endMoreOverWithMessageTipsView:messageTipsView]; +} + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Manager/XHRefreshControl.h b/RefreshControl/Manager/XHRefreshControl.h index b8c7aea..5411571 100644 --- a/RefreshControl/Manager/XHRefreshControl.h +++ b/RefreshControl/Manager/XHRefreshControl.h @@ -108,7 +108,7 @@ - (NSString *)displayAutoLoadMoreRefreshedMessage; /** - * 当scrollView滚动到距离底部有多少距离 + * 13、当scrollView滚动到距离底部有多少距离 * * @return 返回你预期想要的距离,默认是0,即是拖动scrollView到底部才开始加载 */ @@ -156,10 +156,15 @@ - (void)endLoadMoreRefresing; /** - * 没有更多的数据加载 + * 没有更多的数据加载,展示一个提示语 */ - (void)endMoreOverWithMessage:(NSString *)message; +/** + * 没有更多的数据加载,展示一个提示视图 + */ +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView; + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Manager/XHRefreshControl.m b/RefreshControl/Manager/XHRefreshControl.m index ded5259..036fefd 100644 --- a/RefreshControl/Manager/XHRefreshControl.m +++ b/RefreshControl/Manager/XHRefreshControl.m @@ -185,6 +185,13 @@ - (void)endMoreOverWithMessage:(NSString *)message { [self.loadMoreView configuraNothingMoreWithMessage:message]; } +- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView { + [self endLoadMoreRefresing]; + self.noMoreDataForLoaded = YES; + self.handleNetworkError = NO; + [self.loadMoreView configuraNothingMoreWithMessageView:messageTipsView]; +} + /** * 重置是否有更多翻页数据要加载 */ diff --git a/RefreshControl/Views/XHLoadMoreView.h b/RefreshControl/Views/XHLoadMoreView.h index f3fbd54..d737993 100644 --- a/RefreshControl/Views/XHLoadMoreView.h +++ b/RefreshControl/Views/XHLoadMoreView.h @@ -46,4 +46,11 @@ */ - (void)configuraNothingMoreWithMessage:(NSString *)message; +/** + * 当外部加载更多数据的时候,发现没有数据了,可以进行设置一些更有趣的视图 + * + * @param messageView 被显示的目标视图 + */ +- (void)configuraNothingMoreWithMessageView:(UIView *)messageView; + @end diff --git a/RefreshControl/Views/XHLoadMoreView.m b/RefreshControl/Views/XHLoadMoreView.m index 269197a..03bca32 100644 --- a/RefreshControl/Views/XHLoadMoreView.m +++ b/RefreshControl/Views/XHLoadMoreView.m @@ -15,20 +15,35 @@ @interface XHLoadMoreView () */ @property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView; +/** + * 外部定制的提示视图,只有在没有数据的情况下才会出现的 + */ +@property (nonatomic, strong) UIView *messageView; + @end @implementation XHLoadMoreView -- (void)startLoading { +- (void)setupNormalButton { self.loadMoreButton.userInteractionEnabled = NO; self.loadMoreButton.hidden = NO; + [self hideMessageView]; +} + +- (void)hideMessageView { + if (_messageView) { + _messageView.hidden = YES; + } +} + +- (void)startLoading { + [self setupNormalButton]; [self.loadMoreButton setTitle:@"正在载入" forState:UIControlStateNormal]; [self.activityIndicatorView startAnimating]; } - (void)endLoading { - self.loadMoreButton.userInteractionEnabled = NO; - self.loadMoreButton.hidden = NO; + [self setupNormalButton]; [self.loadMoreButton setTitle:@"加载更多" forState:UIControlStateNormal]; [self.activityIndicatorView stopAnimating]; } @@ -36,15 +51,24 @@ - (void)endLoading { - (void)configuraManualStateWithMessage:(NSString *)message { self.loadMoreButton.userInteractionEnabled = YES; self.loadMoreButton.hidden = NO; + [self hideMessageView]; [self.loadMoreButton setTitle:message forState:UIControlStateNormal]; } - (void)configuraNothingMoreWithMessage:(NSString *)message { - self.loadMoreButton.userInteractionEnabled = NO; - self.loadMoreButton.hidden = NO; + [self setupNormalButton]; [self.loadMoreButton setTitle:message forState:UIControlStateNormal]; } +- (void)configuraNothingMoreWithMessageView:(UIView *)messageView { + if (_messageView == messageView) { + _messageView.hidden = NO; + return; + } + self.messageView = messageView; + [self addSubview:self.messageView]; +} + - (void)setupCustomLoadMoreButton:(UIButton *)customLoadMoreButton { customLoadMoreButton.frame = self.loadMoreButton.frame; if (_loadMoreButton) { diff --git a/XHRefreshControlExample/XHRefreshControlExample.xcodeproj/project.pbxproj b/XHRefreshControlExample/XHRefreshControlExample.xcodeproj/project.pbxproj index 472652b..bf97493 100644 --- a/XHRefreshControlExample/XHRefreshControlExample.xcodeproj/project.pbxproj +++ b/XHRefreshControlExample/XHRefreshControlExample.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ AB9483A419721E8D001BC1FD /* XHRootTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB94839A19721E8D001BC1FD /* XHRootTableViewController.m */; }; AB9483A519721E8D001BC1FD /* XHSegmentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AB94839D19721E8D001BC1FD /* XHSegmentViewController.m */; }; AB9483A619721E8D001BC1FD /* XHSegueItem.m in Sources */ = {isa = PBXBuildFile; fileRef = AB9483A019721E8D001BC1FD /* XHSegueItem.m */; }; + E4E0DCD81AE144F700B23B93 /* nothing_more_tips@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E4E0DCD71AE144F700B23B93 /* nothing_more_tips@2x.png */; }; F7CDBF4E1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F7CDBF4D1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.m */; }; /* End PBXBuildFile section */ @@ -120,6 +121,7 @@ AB94839D19721E8D001BC1FD /* XHSegmentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSegmentViewController.m; sourceTree = ""; }; AB94839F19721E8D001BC1FD /* XHSegueItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSegueItem.h; sourceTree = ""; }; AB9483A019721E8D001BC1FD /* XHSegueItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSegueItem.m; sourceTree = ""; }; + E4E0DCD71AE144F700B23B93 /* nothing_more_tips@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "nothing_more_tips@2x.png"; sourceTree = ""; }; F7CDBF4C1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSimulationNetEaseNetworkErrorViewController.h; sourceTree = ""; }; F7CDBF4D1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSimulationNetEaseNetworkErrorViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -151,10 +153,10 @@ 4755DE7319C498CA0088B5D2 /* SystemCollectionViewController */ = { isa = PBXGroup; children = ( - 7D6DF80719C8704100405BCB /* XHSystemRefreshCollectionViewController.h */, - 7D6DF80819C8704100405BCB /* XHSystemRefreshCollectionViewController.m */, 4755DE7619C498FC0088B5D2 /* XHSystemCollectionViewController.h */, 4755DE7719C498FC0088B5D2 /* XHSystemCollectionViewController.m */, + 7D6DF80719C8704100405BCB /* XHSystemRefreshCollectionViewController.h */, + 7D6DF80819C8704100405BCB /* XHSystemRefreshCollectionViewController.m */, ); path = SystemCollectionViewController; sourceTree = ""; @@ -229,6 +231,7 @@ AB0B345619429D4700EC0072 /* Supporting Files */ = { isa = PBXGroup; children = ( + E4E0DCD71AE144F700B23B93 /* nothing_more_tips@2x.png */, AB0B345719429D4700EC0072 /* XHRefreshControlExample-Info.plist */, AB0B345819429D4700EC0072 /* InfoPlist.strings */, AB0B345B19429D4700EC0072 /* main.m */, @@ -484,6 +487,7 @@ 7D093BAD1963FE1100F563BD /* NSDateTimeAgo.bundle in Resources */, AB0B346B19429D4700EC0072 /* Images.xcassets in Resources */, AB0B345A19429D4700EC0072 /* InfoPlist.strings in Resources */, + E4E0DCD81AE144F700B23B93 /* nothing_more_tips@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/XHRefreshControlExample/XHRefreshControlExample/Controllers/CollectionViewController/DemoCollectionViewController.m b/XHRefreshControlExample/XHRefreshControlExample/Controllers/CollectionViewController/DemoCollectionViewController.m index cc8eef0..09c6d7f 100644 --- a/XHRefreshControlExample/XHRefreshControlExample/Controllers/CollectionViewController/DemoCollectionViewController.m +++ b/XHRefreshControlExample/XHRefreshControlExample/Controllers/CollectionViewController/DemoCollectionViewController.m @@ -46,17 +46,24 @@ - (id)initWithFrame:(CGRect)frame { @interface DemoCollectionViewController () +@property (nonatomic, strong) UIImageView *messageTipsView; + @end @implementation DemoCollectionViewController - (void)loadDataSource { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (self.requestCurrentPage > 0) { + [self.dataSource addObjectsFromArray:@[@"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @""]]; [self.collectionView reloadData]; [self endLoadMoreRefreshing]; + if (self.requestCurrentPage == 5) { + [self endMoreOverWithMessageTipsView:self.messageTipsView]; + return ; + } } else { self.dataSource = [@[@"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @""] mutableCopy]; [self.collectionView reloadData]; @@ -81,20 +88,39 @@ - (void)viewDidAppear:(BOOL)animated { } } -- (void)viewDidLoad -{ +- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. - self.collectionView.backgroundColor = [UIColor whiteColor]; + self.collectionView.backgroundColor = [UIColor colorWithRed:248/255.0 green:249/255.0 blue:251/255.0 alpha:1.0]; [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"CollectionViewCell"]; } -- (void)didReceiveMemoryWarning -{ +- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } +#pragma mark - Propertys + +- (UIImageView *)messageTipsView { + if (!_messageTipsView) { + _messageTipsView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), 50)]; + _messageTipsView.image = [UIImage imageNamed:@"nothing_more_tips"]; + } + return _messageTipsView; +} + +#pragma mark - XHRefreshControl Delegate + +- (UIButton *)customLoadMoreButton { + UIButton *_loadMoreButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 5, CGRectGetWidth(self.view.bounds) - 20, CGRectGetHeight(self.view.bounds) - 10)]; + [_loadMoreButton setTitle:@"加载更多" forState:UIControlStateNormal]; + _loadMoreButton.titleLabel.font = [UIFont systemFontOfSize:16]; + [_loadMoreButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [_loadMoreButton setBackgroundColor:[UIColor colorWithRed:248/255.0 green:249/255.0 blue:251/255.0 alpha:1.0]]; + return _loadMoreButton; +} + #pragma mark - CollectionView Delegate - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { diff --git a/XHRefreshControlExample/XHRefreshControlExample/Controllers/DemoTableViewController/XHDemoTableViewController.m b/XHRefreshControlExample/XHRefreshControlExample/Controllers/DemoTableViewController/XHDemoTableViewController.m index 4ffce87..9d7fbf4 100644 --- a/XHRefreshControlExample/XHRefreshControlExample/Controllers/DemoTableViewController/XHDemoTableViewController.m +++ b/XHRefreshControlExample/XHRefreshControlExample/Controllers/DemoTableViewController/XHDemoTableViewController.m @@ -12,6 +12,8 @@ @interface XHDemoTableViewController () +@property (nonatomic, strong) UIImageView *messageTipsView; + @end @implementation XHDemoTableViewController @@ -72,6 +74,16 @@ - (void)didReceiveMemoryWarning // Dispose of any resources that can be recreated. } +#pragma mark - Propertys + +- (UIImageView *)messageTipsView { + if (!_messageTipsView) { + _messageTipsView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]), 50)]; + _messageTipsView.image = [UIImage imageNamed:@"nothing_more_tips"]; + } + return _messageTipsView; +} + #pragma mark - XHRefreshControl Delegate - (NSString *)lastUpdateTimeString { diff --git a/XHRefreshControlExample/XHRefreshControlExample/nothing_more_tips@2x.png b/XHRefreshControlExample/XHRefreshControlExample/nothing_more_tips@2x.png new file mode 100644 index 0000000..a81ba44 Binary files /dev/null and b/XHRefreshControlExample/XHRefreshControlExample/nothing_more_tips@2x.png differ