Commit fa1ce203 authored by 汪洋's avatar 汪洋

Merge branch 'ajp/list-page' into 'master'

添加page、count字段

See merge request !11
parents 772cf88e bafe660f
......@@ -134,7 +134,9 @@
}
- (void)refreshList{
[self.viewModel setStartNum:0];
[self.viewModel setPage:1];
[[self.viewModel dataArray] removeAllObjects];
[_collectionView reloadData];
......
......@@ -92,7 +92,9 @@
}
- (void)refreshList{
[self.viewModel setStartNum:0];
[self.viewModel setPage:1];
[[self.viewModel dataArray] removeAllObjects];
[_table reloadData];
......
......@@ -98,6 +98,12 @@
/** @brief 获取http数据分页第一页起始位置,默认为0,下一页为startNum+每页的数据条数(默认为10) */
@property (nonatomic,assign) NSInteger startNum;
/** @brief 获取http数据,按照页码进行获取(默认为1) */
@property (nonatomic,assign) NSInteger page;
/** @brief 获取http数据,每页获取数据(默认为10) */
@property (nonatomic,assign) NSInteger count;
/** @brief 请求返回的数据,用于TableView的DataSource */
/** @brief 请求数据是否成功 */@property (nonatomic,strong) NSMutableArray *dataArray;
......
......@@ -20,6 +20,8 @@
_dataArray = [[NSMutableArray alloc] init];
_startNum = 0;
_params = nil;
_page = 1;
_count = 10;
_deduplicationDic = [NSMutableDictionary dictionary];
_fetchDataErrorMsg = @"获取数据失败,请重试";
_fetchDataNilMsg = @"暂时没有相关数据";
......@@ -36,11 +38,11 @@
*/
- (void)buildParams{
_params = @{@"start_num":@(self.startNum),
@"count":@(10)};
@"count":@(self.count)};
}
- (BOOL)shouldClearDataForResponse:(id)response{
return self.startNum == 0;
return self.startNum == 0 && self.page == 1;
}
- (void)fetchRemoteData{
......@@ -65,8 +67,8 @@
NSArray *array = (NSArray *)responseObject;
[self buildModelWithRemoteArray:array];
self.page++;
[self setValue:@YES forKey:@"fetchDataSuccess"];
}else if([responseObject isKindOfClass:[NSDictionary class]]){
NSDictionary *dic = (NSDictionary *)responseObject;
......@@ -74,10 +76,12 @@
self.message = responseObject[@"message"];
if (code == APIStatusCodeSuccess) {
[self buildModelWithRemoteDic:dic];
self.page++;
[self setValue:@YES forKey:@"fetchDataSuccess"];
}else if (code == APIStatusCodeEmpty){
self.message = responseObject[@"message"];
self.page++;
[self setValue:@YES forKey:@"fetchDataSuccess"];
}else{
......@@ -100,6 +104,7 @@
// 因为 clearData 可能会被外部调用,所以 self.startNum = 0 要确认执行,不能少
self.startNum = 0;
_deleteCount = 0;
self.page = 1;
[self.dataArray removeAllObjects];
[_deduplicationDic removeAllObjects];
}
......@@ -107,6 +112,7 @@
- (void)handleHeaderRefreshing
{
self.startNum = 0;
self.page = 1;
[self fetchRemoteData];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment