Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMBase
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMBase
Commits
fa1ce203
Commit
fa1ce203
authored
Nov 21, 2018
by
汪洋
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ajp/list-page' into 'master'
添加page、count字段 See merge request
!11
parents
772cf88e
bafe660f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
3 deletions
+19
-3
WMBaseCollectionController.m
GMBase/Classes/WMBaseCollectionController.m
+2
-0
WMBaseListViewController.m
GMBase/Classes/WMBaseListViewController.m
+2
-0
WMFetchDataViewModel.h
GMBase/Classes/WMFetchDataViewModel.h
+6
-0
WMFetchDataViewModel.m
GMBase/Classes/WMFetchDataViewModel.m
+9
-3
No files found.
GMBase/Classes/WMBaseCollectionController.m
View file @
fa1ce203
...
...
@@ -134,7 +134,9 @@
}
-
(
void
)
refreshList
{
[
self
.
viewModel
setStartNum
:
0
];
[
self
.
viewModel
setPage
:
1
];
[[
self
.
viewModel
dataArray
]
removeAllObjects
];
[
_collectionView
reloadData
];
...
...
GMBase/Classes/WMBaseListViewController.m
View file @
fa1ce203
...
...
@@ -92,7 +92,9 @@
}
-
(
void
)
refreshList
{
[
self
.
viewModel
setStartNum
:
0
];
[
self
.
viewModel
setPage
:
1
];
[[
self
.
viewModel
dataArray
]
removeAllObjects
];
[
_table
reloadData
];
...
...
GMBase/Classes/WMFetchDataViewModel.h
View file @
fa1ce203
...
...
@@ -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
;
...
...
GMBase/Classes/WMFetchDataViewModel.m
View file @
fa1ce203
...
...
@@ -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
];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment