1010#import " ProjectListTaCell.h"
1111#import " ODRefreshControl.h"
1212#import " Coding_NetAPIManager.h"
13+ #import " SVPullToRefresh.h"
1314
1415#import " Login.h"
1516
@@ -29,6 +30,8 @@ @interface CSTopiclistView()<SWTableViewCellDelegate>
2930@property (nonatomic ,assign )CSMyTopicsType type;
3031
3132@property (nonatomic ,assign )BOOL isLodding;
33+ @property (nonatomic , assign ) BOOL hasMore;
34+ @property (nonatomic , assign ) NSInteger curPage;
3235
3336@end
3437
@@ -38,6 +41,8 @@ - (id)initWithFrame:(CGRect)frame type:(CSMyTopicsType )type block:(TopicListVie
3841 self = [super initWithFrame: frame];
3942 if (self) {
4043 // Initialization code
44+ _dataList = [[NSMutableArray alloc ] init ];
45+ _type = type;
4146 _block = block;
4247 _myTableView = ({
4348 UITableView *tableView = [[UITableView alloc ] init ];
@@ -46,6 +51,12 @@ - (id)initWithFrame:(CGRect)frame type:(CSMyTopicsType )type block:(TopicListVie
4651 tableView.dataSource = self;
4752 [tableView registerClass: [CSTopicCell class ] forCellReuseIdentifier: kCellIdentifier_TopicCell ];
4853 tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
54+ {
55+ __weak typeof (self) weakSelf = self;
56+ [tableView addInfiniteScrollingWithActionHandler: ^{
57+ [weakSelf loadMore ];
58+ }];
59+ }
4960 [self addSubview: tableView];
5061 [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
5162 make.edges .equalTo (self);
@@ -58,8 +69,11 @@ - (id)initWithFrame:(CGRect)frame type:(CSMyTopicsType )type block:(TopicListVie
5869 tableView;
5970 });
6071
61- _myRefreshControl = [[ODRefreshControl alloc ] initInScrollView: self .myTableView];
62- [_myRefreshControl addTarget: self action: @selector (refresh ) forControlEvents: UIControlEventValueChanged];
72+ // _myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
73+ // [_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
74+
75+ self.hasMore = YES ;
76+ self.curPage = 1 ;
6377
6478 if (_myTopic.count > 0 ) {
6579 [_myTableView reloadData ];
@@ -107,28 +121,44 @@ - (void)refresh{
107121 [self sendRequest ];
108122}
109123
124+ - (void )loadMore {
125+
126+ if (self.isLodding ) {
127+ return ;
128+ }
129+
130+ ++self.curPage ;
131+ [self sendRequest ];
132+ }
133+
110134- (void )sendRequest {
111135 if (_dataList.count <= 0 ) {
112136 [self beginLoading ];
113137 }
114138 __weak typeof (self) weakSelf = self;
115139
116- if (_type == CSMyTopicsTypeJoined) {
117- [[Coding_NetAPIManager sharedManager ] request_WatchedTopicsWithUserGK: [Login curLoginUser ].global_key block: ^(id data, NSError *error) {
140+ if (_type == CSMyTopicsTypeWatched) {
141+ [[Coding_NetAPIManager sharedManager ] request_WatchedTopicsWithUserGK: [Login curLoginUser ].global_key page: self .curPage block: ^(id data, BOOL hasMoreData, NSError *error) {
142+ weakSelf.hasMore = hasMoreData;
118143 [weakSelf doAfterGotResultWithData: data error: error];
119144 }];
120145 }else {
121- [[Coding_NetAPIManager sharedManager ] request_JoinedTopicsWithUserGK: [Login curLoginUser ].global_key block: ^(id data, NSError *error) {
122- [weakSelf doAfterGotResultWithData: data error: error];
146+ [[Coding_NetAPIManager sharedManager ] request_JoinedTopicsWithUserGK: [Login curLoginUser ].global_key page: self .curPage block: ^(id data, BOOL hasMoreData, NSError *error) {
147+ weakSelf.hasMore = hasMoreData;
148+ [weakSelf doAfterGotResultWithData: data error: error];
123149 }];
124150 }
125151}
126152
127- - (void )doAfterGotResultWithData : (id ) data error : (NSError *)error {
153+ - (void )doAfterGotResultWithData : (id ) data error : (NSError *)error {
154+
155+ [self .myTableView.infiniteScrollingView stopAnimating ];
128156 [self .myRefreshControl endRefreshing ];
129157 [self endLoading ];
130158 if (data) {
131- _dataList = data[@" list" ];
159+
160+ [_dataList addObjectsFromArray: [data[@" list" ] copy ]];
161+ self.myTableView .showsInfiniteScrolling = self.hasMore ;
132162 [self .myTableView reloadData ];
133163 }
134164// EaseBlankPageType blankPageType;
0 commit comments