Skip to content

Commit 591460a

Browse files
committed
我的话题分页
1 parent 2efef90 commit 591460a

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

Coding_iOS/Controllers/Topic/CSTopiclistView.m

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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;

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ typedef NS_ENUM(NSUInteger, VerifyType){
218218

219219
- (void)request_TopicDetailsWithTopicID:(int)topicID block:(void (^)(id data, NSError *error))block;
220220

221-
- (void)request_JoinedTopicsWithUserGK:(NSString *)userGK block:(void (^)(id data, NSError *error))block;
222-
- (void)request_WatchedTopicsWithUserGK:(NSString *)userGK block:(void (^)(id data, NSError *error))block;
221+
- (void)request_JoinedTopicsWithUserGK:(NSString *)userGK page:(NSInteger)page block:(void (^)(id data, BOOL hasMoreData, NSError *error))block;
222+
- (void)request_WatchedTopicsWithUserGK:(NSString *)userGK page:(NSInteger)page block:(void (^)(id data, BOOL hasMoreData, NSError *error))block;
223223

224224
- (void)request_Topic_DoWatch_WithUrl:(NSString *)url andBlock:(void (^)(id data, NSError *error))block;
225225

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,29 +2046,31 @@ - (void)request_TopicDetailsWithTopicID:(int)topicID block:(void (^)(id data, NS
20462046
}
20472047

20482048

2049-
- (void)request_JoinedTopicsWithUserGK:(NSString *)userGK block:(void (^)(id data, NSError *error))block {
2050-
NSString *path = [NSString stringWithFormat:@"api/user/%@/tweet_topic/joined",userGK];
2049+
- (void)request_JoinedTopicsWithUserGK:(NSString *)userGK page:(NSInteger)page block:(void (^)(id data, BOOL hasMoreData, NSError *error))block {
2050+
NSString *path = [[NSString stringWithFormat:@"api/user/%@/tweet_topic/joined",userGK] stringByAppendingString:[NSString stringWithFormat:@"?page=%d", (int)page]];
20512051
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
20522052
if(data) {
20532053
id resultData = data[@"data"];
2054-
block(resultData, nil);
2054+
BOOL hasMoreData = [resultData[@"totalPage"] intValue] - [resultData[@"page"] intValue];
2055+
block(resultData, hasMoreData, nil);
20552056
// NSArray *list = data[@"data"][@"list"];
20562057
// NSArray *resultA = [NSObject arrayFromJSON:resultData ofObjects:@"ProjectActivity"];
20572058
// block(resultA, nil);
20582059
}else {
2059-
block(nil, error);
2060+
block(nil, NO, error);
20602061
}
20612062
}];
20622063
}
20632064

2064-
- (void)request_WatchedTopicsWithUserGK:(NSString *)userGK block:(void (^)(id data, NSError *error))block {
2065-
NSString *path = [NSString stringWithFormat:@"/api/user/%@/tweet_topic/watched",userGK];
2065+
- (void)request_WatchedTopicsWithUserGK:(NSString *)userGK page:(NSInteger)page block:(void (^)(id data, BOOL hasMoreData, NSError *error))block {
2066+
NSString *path = [[NSString stringWithFormat:@"/api/user/%@/tweet_topic/watched",userGK] stringByAppendingString:[NSString stringWithFormat:@"?page=%d", (int)page]];
20662067
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
20672068
if(data) {
20682069
id resultData = data[@"data"];
2069-
block(resultData, nil);
2070+
BOOL hasMoreData = [resultData[@"totalPage"] intValue] - [resultData[@"page"] intValue];
2071+
block(resultData, hasMoreData, nil);
20702072
}else {
2071-
block(nil, error);
2073+
block(nil, NO, error);
20722074
}
20732075
}];
20742076
}

0 commit comments

Comments
 (0)