Skip to content

Commit

Permalink
Merge pull request #12 from LacieJiang/CollectionView
Browse files Browse the repository at this point in the history
Add RefreshCollectionViewController
  • Loading branch information
xhzengAIB committed Sep 16, 2014
2 parents 941d110 + 50d2963 commit 4bd8693
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 0 deletions.
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
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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
4755DE7819C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4755DE7519C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.m */; };
4755DE7919C498FC0088B5D2 /* XHSystemCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4755DE7719C498FC0088B5D2 /* XHSystemCollectionViewController.m */; };
7D093BAC1963FE1100F563BD /* NSDate+TimeAgo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D093BAA1963FE1100F563BD /* NSDate+TimeAgo.m */; };
7D093BAD1963FE1100F563BD /* NSDateTimeAgo.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 7D093BAB1963FE1100F563BD /* NSDateTimeAgo.bundle */; };
AB0B345019429D4700EC0072 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0B344F19429D4700EC0072 /* Foundation.framework */; };
Expand Down Expand Up @@ -51,6 +53,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
4755DE7419C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSysatemRefreshCollectionViewController.h; sourceTree = "<group>"; };
4755DE7519C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSysatemRefreshCollectionViewController.m; sourceTree = "<group>"; };
4755DE7619C498FC0088B5D2 /* XHSystemCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHSystemCollectionViewController.h; sourceTree = "<group>"; };
4755DE7719C498FC0088B5D2 /* XHSystemCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHSystemCollectionViewController.m; sourceTree = "<group>"; };
7D093BA91963FE1100F563BD /* NSDate+TimeAgo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+TimeAgo.h"; sourceTree = "<group>"; };
7D093BAA1963FE1100F563BD /* NSDate+TimeAgo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+TimeAgo.m"; sourceTree = "<group>"; };
7D093BAB1963FE1100F563BD /* NSDateTimeAgo.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = NSDateTimeAgo.bundle; sourceTree = "<group>"; };
Expand Down Expand Up @@ -131,6 +137,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4755DE7319C498CA0088B5D2 /* SystemCollectionViewController */ = {
isa = PBXGroup;
children = (
4755DE7419C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.h */,
4755DE7519C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.m */,
4755DE7619C498FC0088B5D2 /* XHSystemCollectionViewController.h */,
4755DE7719C498FC0088B5D2 /* XHSystemCollectionViewController.m */,
);
path = SystemCollectionViewController;
sourceTree = "<group>";
};
7D093BA81963FE1100F563BD /* Vendor */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -229,6 +246,7 @@
AB94835E19721DE0001BC1FD /* Controllers */ = {
isa = PBXGroup;
children = (
4755DE7319C498CA0088B5D2 /* SystemCollectionViewController */,
AB94835F19721DE0001BC1FD /* CustomTableViewController */,
AB94836A19721DE0001BC1FD /* SystemTableViewController */,
);
Expand Down Expand Up @@ -449,6 +467,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4755DE7919C498FC0088B5D2 /* XHSystemCollectionViewController.m in Sources */,
AB94838B19721DE0001BC1FD /* XHLoadMoreView.m in Sources */,
AB94838619721DE0001BC1FD /* XHSysatemRefreshTableViewController.m in Sources */,
AB94838719721DE0001BC1FD /* XHSystemTableViewController.m in Sources */,
Expand All @@ -461,6 +480,7 @@
AB94838019721DE0001BC1FD /* XHBaseTableViewController.m in Sources */,
AB94838319721DE0001BC1FD /* XHFoundationCommon.m in Sources */,
AB94838D19721DE0001BC1FD /* XHRefreshCircleContainerView.m in Sources */,
4755DE7819C498FC0088B5D2 /* XHSysatemRefreshCollectionViewController.m in Sources */,
AB9483A619721E8D001BC1FD /* XHSegueItem.m in Sources */,
AB94838919721DE0001BC1FD /* XHActivityCircleIndicatorView.m in Sources */,
AB9483A419721E8D001BC1FD /* XHRootTableViewController.m in Sources */,
Expand Down

0 comments on commit 4bd8693

Please sign in to comment.