Skip to content

Commit

Permalink
添加一个自定义无更多数据的提示视图功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xhzengAIB committed Apr 17, 2015
1 parent 86ed996 commit 4863010
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,24 @@
- (void)endPullDownRefreshing;

/**
* 当上啦加载数据完成后,你也得调用该方法哦!然后你可能会问,那我要怎么判断是下拉还是上啦啊?requestCurrentPage看这个变量,会跟着变化哦!
* 当上拉加载数据完成后,你也得调用该方法哦!然后你可能会问,那我要怎么判断是下拉还是上啦啊?requestCurrentPage看这个变量,会跟着变化哦!
*/
- (void)endLoadMoreRefreshing;

/**
* 当上啦加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦!
* 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦!
*
* @param message 提示用户的信息
*/
- (void)endMoreOverWithMessage:(NSString *)message;

/**
* 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦!
*
* @param messageTipsView 提示用户的视图
*/
- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView;

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
*/
- (void)endMoreOverWithMessage:(NSString *)message;

/**
* 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦!
*
* @param messageTipsView 提示用户的视图
*/
- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView;

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
*/
- (void)endMoreOverWithMessage:(NSString *)message;

/**
* 当上拉加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦!
*
* @param messageTipsView 提示用户的视图
*/
- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView;

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ - (void)endMoreOverWithMessage:(NSString *)message {
[self.customRefreshControl endMoreOverWithMessage:message];
}

- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView {
[self.customRefreshControl endMoreOverWithMessageTipsView:messageTipsView];
}

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
9 changes: 7 additions & 2 deletions RefreshControl/Manager/XHRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
- (NSString *)displayAutoLoadMoreRefreshedMessage;

/**
* 当scrollView滚动到距离底部有多少距离
* 13、当scrollView滚动到距离底部有多少距离
*
* @return 返回你预期想要的距离,默认是0,即是拖动scrollView到底部才开始加载
*/
Expand Down Expand Up @@ -156,10 +156,15 @@
- (void)endLoadMoreRefresing;

/**
* 没有更多的数据加载
* 没有更多的数据加载,展示一个提示语
*/
- (void)endMoreOverWithMessage:(NSString *)message;

/**
* 没有更多的数据加载,展示一个提示视图
*/
- (void)endMoreOverWithMessageTipsView:(UIView *)messageTipsView;

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
7 changes: 7 additions & 0 deletions RefreshControl/Manager/XHRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

/**
* 重置是否有更多翻页数据要加载
*/
Expand Down
7 changes: 7 additions & 0 deletions RefreshControl/Views/XHLoadMoreView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@
*/
- (void)configuraNothingMoreWithMessage:(NSString *)message;

/**
* 当外部加载更多数据的时候,发现没有数据了,可以进行设置一些更有趣的视图
*
* @param messageView 被显示的目标视图
*/
- (void)configuraNothingMoreWithMessageView:(UIView *)messageView;

@end
34 changes: 29 additions & 5 deletions RefreshControl/Views/XHLoadMoreView.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,60 @@ @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];
}

- (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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -120,6 +121,7 @@
AB94839D19721E8D001BC1FD /* XHSegmentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSegmentViewController.m; sourceTree = "<group>"; };
AB94839F19721E8D001BC1FD /* XHSegueItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSegueItem.h; sourceTree = "<group>"; };
AB9483A019721E8D001BC1FD /* XHSegueItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSegueItem.m; sourceTree = "<group>"; };
E4E0DCD71AE144F700B23B93 /* nothing_more_tips@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "nothing_more_tips@2x.png"; sourceTree = "<group>"; };
F7CDBF4C1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSimulationNetEaseNetworkErrorViewController.h; sourceTree = "<group>"; };
F7CDBF4D1A5BCB8300DE641D /* XHSimulationNetEaseNetworkErrorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSimulationNetEaseNetworkErrorViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@interface XHDemoTableViewController ()

@property (nonatomic, strong) UIImageView *messageTipsView;

@end

@implementation XHDemoTableViewController
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4863010

Please sign in to comment.