-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from LacieJiang/CollectionView
Add RefreshCollectionViewController
- Loading branch information
Showing
5 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// XHSystemCollectionViewController.h | ||
// XHRefreshControlExample | ||
// | ||
// Created by Jiangliyin on 14-9-14. | ||
// Copyright (c) 2014年 曾宪华 QQ群: (142557668) QQ:543413507 Gmail:[email protected]. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface XHSystemCollectionViewController : UICollectionViewController | ||
|
||
/** | ||
* 大量数据的数据源 | ||
*/ | ||
@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 |
38 changes: 38 additions & 0 deletions
38
RefreshControl/Controllers/SystemCollectionViewController/XHSystemCollectionViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// XHSystemCollectionViewController.m | ||
// XHRefreshControlExample | ||
// | ||
// Created by Jiangliyin on 14-9-14. | ||
// Copyright (c) 2014年 曾宪华 QQ群: (142557668) QQ:543413507 Gmail:[email protected]. All rights reserved. | ||
// | ||
|
||
#import "XHSystemCollectionViewController.h" | ||
|
||
@interface XHSystemCollectionViewController () | ||
|
||
|
||
@end | ||
|
||
@implementation XHSystemCollectionViewController | ||
|
||
#pragma mark - Publish Method | ||
|
||
- (void)loadDataSource { | ||
// in subClass | ||
} | ||
|
||
#pragma mark - UITableView DataSource | ||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { | ||
return 1; | ||
} | ||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { | ||
return self.dataSource.count; | ||
} | ||
|
||
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: | ||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { | ||
// in subClass | ||
return nil; | ||
} | ||
|
||
@end |
84 changes: 84 additions & 0 deletions
84
...trol/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// XHSystemCollectionViewController.h | ||
// XHRefreshControlExample | ||
// | ||
// Created by Jiangliyin on 14-9-14. | ||
// Copyright (c) 2014年 曾宪华 QQ群: (142557668) QQ:543413507 Gmail:[email protected]. All rights reserved. | ||
// | ||
|
||
#import "XHSystemCollectionViewController.h" | ||
|
||
#import "XHRefreshControl.h" | ||
|
||
@interface XHSystemRefreshCollectionViewController : XHSystemCollectionViewController <XHRefreshControlDelegate> | ||
|
||
/** | ||
* 是否支持下拉刷新 | ||
*/ | ||
@property (nonatomic, assign) BOOL pullDownRefreshed; | ||
|
||
/** | ||
* 是否支持上拉刷新 | ||
*/ | ||
@property (nonatomic, assign) BOOL loadMoreRefreshed; | ||
|
||
/** | ||
* 下拉刷新的样式 | ||
*/ | ||
@property (nonatomic, assign) XHPullDownRefreshViewType refreshViewType; | ||
|
||
/** | ||
* 加载数据的页码 | ||
*/ | ||
@property (nonatomic, assign) NSInteger requestCurrentPage; | ||
|
||
/** | ||
* 是否显示下拉刷新的标签文本,如果返回YES,按照正常排版,如果返回NO,那转圈居中,默认是YES | ||
*/ | ||
@property (nonatomic, assign) BOOL hasStatusLabelShowed; | ||
|
||
/** | ||
* 圆圈的颜色,默认是[UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1] | ||
*/ | ||
@property (nonatomic, strong) UIColor *circleColor; | ||
|
||
/** | ||
* 圆圈的线条粗细,默认为1, 最大为2 | ||
*/ | ||
@property (nonatomic, assign) CGFloat circleLineWidth; | ||
|
||
/** | ||
* 自动下拉刷新调用的方法,必须放在viewDidAppear方法内,别把这行代码放到别处,然后导致了错误,那就不好了嘛! | ||
*/ | ||
- (void)startPullDownRefreshing; | ||
|
||
/** | ||
* 当下拉加载数据完成后,你必须调用该方法哦! | ||
*/ | ||
- (void)endPullDownRefreshing; | ||
|
||
/** | ||
* 当上啦加载数据完成后,你也得调用该方法哦!然后你可能会问,那我要怎么判断是下拉还是上啦啊?requestCurrentPage看这个变量,会跟着变化哦! | ||
*/ | ||
- (void)endLoadMoreRefreshing; | ||
|
||
/** | ||
* 当上啦加载数据回调告诉我们,已经没有下一页了,那你可以调用该方法,告诉用户你已经没有数据了哦! | ||
* | ||
* @param message 提示用户的信息 | ||
*/ | ||
- (void)endMoreOverWithMessage:(NSString *)message; | ||
|
||
/** | ||
* 当网络加载失败的时候,你必须调用该方法,如果你不调用,我也帮不了你了 | ||
*/ | ||
- (void)handleLoadMoreError; | ||
|
||
/** | ||
* 获取当前是否在加载数据中 | ||
* | ||
* @return 返回预期结果 | ||
*/ | ||
- (BOOL)isLoadingDataSource; | ||
|
||
@end |
127 changes: 127 additions & 0 deletions
127
...trol/Controllers/SystemCollectionViewController/XHSystemRefreshCollectionViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// | ||
// XHSystemCollectionViewController.m | ||
// XHRefreshControlExample | ||
// | ||
// Created by Jiangliyin on 14-9-14. | ||
// Copyright (c) 2014年 曾宪华 QQ群: (142557668) QQ:543413507 Gmail:[email protected]. All rights reserved. | ||
// | ||
|
||
#import "XHSystemRefreshCollectionViewController.h" | ||
|
||
@interface XHSystemRefreshCollectionViewController () | ||
|
||
@property (nonatomic, strong) XHRefreshControl *customRefreshControl; | ||
|
||
@end | ||
|
||
@implementation XHSystemRefreshCollectionViewController | ||
|
||
- (void)startPullDownRefreshing { | ||
[self.customRefreshControl startPullDownRefreshing]; | ||
} | ||
|
||
- (void)endPullDownRefreshing { | ||
[self.customRefreshControl endPullDownRefreshing]; | ||
} | ||
|
||
- (void)endLoadMoreRefreshing { | ||
[self.customRefreshControl endLoadMoreRefresing]; | ||
} | ||
|
||
- (void)endMoreOverWithMessage:(NSString *)message { | ||
[self.customRefreshControl endMoreOverWithMessage:message]; | ||
} | ||
|
||
- (void)handleLoadMoreError { | ||
[self.customRefreshControl handleLoadMoreError]; | ||
} | ||
|
||
- (BOOL)isLoadingDataSource { | ||
return [self.customRefreshControl isLoading]; | ||
} | ||
|
||
#pragma mark - Life Cycle | ||
|
||
- (void)setupRefreshControl { | ||
if (!_customRefreshControl) { | ||
_customRefreshControl = [[XHRefreshControl alloc] initWithScrollView:self.collectionView delegate:self]; | ||
_customRefreshControl.hasStatusLabelShowed = self.hasStatusLabelShowed; | ||
_customRefreshControl.circleColor = self.circleColor; | ||
_customRefreshControl.circleLineWidth = self.circleLineWidth; | ||
} | ||
} | ||
|
||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
self.pullDownRefreshed = YES; | ||
self.loadMoreRefreshed = YES; | ||
self.circleColor = [UIColor colorWithRed:173 / 255.0 green:53 / 255.0 blue:60 / 255.0 alpha:1]; | ||
self.circleLineWidth = 1.0; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)viewDidAppear:(BOOL)animated { | ||
[super viewDidAppear:animated]; | ||
|
||
if (self.pullDownRefreshed) { | ||
[self setupRefreshControl]; | ||
} | ||
} | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view. | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
- (void)dealloc { | ||
|
||
} | ||
|
||
#pragma mark - XHRefreshControl Delegate | ||
|
||
- (void)beginPullDownRefreshing { | ||
self.requestCurrentPage = 0; | ||
[self loadDataSource]; | ||
} | ||
|
||
- (void)beginLoadMoreRefreshing { | ||
self.requestCurrentPage ++; | ||
[self loadDataSource]; | ||
} | ||
|
||
- (NSDate *)lastUpdateTime { | ||
return [NSDate date]; | ||
} | ||
|
||
- (NSInteger)autoLoadMoreRefreshedCountConverManual { | ||
return 2; | ||
} | ||
|
||
- (BOOL)isPullDownRefreshed { | ||
return self.pullDownRefreshed; | ||
} | ||
|
||
- (BOOL)isLoadMoreRefreshed { | ||
return self.loadMoreRefreshed; | ||
} | ||
|
||
- (XHRefreshViewLayerType)refreshViewLayerType { | ||
return XHRefreshViewLayerTypeOnScrollViews; | ||
} | ||
|
||
- (XHPullDownRefreshViewType)pullDownRefreshViewType { | ||
return XHPullDownRefreshViewTypeActivityIndicator; | ||
} | ||
|
||
- (NSString *)displayAutoLoadMoreRefreshedMessage { | ||
return @"点击显示下10条"; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters