objective-c - iOS怎样通过这样的JSON数据,实现上下拉刷新加载更多
ringa_lee
ringa_lee 2017-04-17 15:01:51
0
1
534

{
"count": 87,
"next": "http://127.0.0.1:5000/api/v1.0/posts/?page=2",
"posts": [
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "\u66f4\u597d\u6591\u6591\u9a73\u9a73\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d\u4e0d",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/1/comments/",
"id": 1,
"timestamp": "Wed, 24 Jun 2015 06:40:03 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/1"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "\u770b\u770b\u770b\u770b\u5361\u5361\u5361\u5361\u9760\u9760\u9760\u9760\u9760\u9760\u9760",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/2/comments/",
"id": 2,
"timestamp": "Wed, 24 Jun 2015 06:40:31 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/2"
},
{
"author": "http://127.0.0.1:5000/api/v1.0/users/2",
"body": "uuuuuuuuuuuuuuuuuuu\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684\u6de1\u6de1\u7684",
"body_html": null,
"body_title": null,
"comment_count": 0,
"comments": "http://127.0.0.1:5000/api/v1.0/posts/3/comments/",
"id": 3,
"timestamp": "Wed, 24 Jun 2015 06:40:44 GMT",
"url": "http://127.0.0.1:5000/api/v1.0/posts/3"
}
],
"prev": null
}

请问怎样通过这样的JSON数据,实现下拉刷新加载更多,是要判断id吗?还是创建时间?或者输出怎样的JSON数据更方便一些?

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
大家讲道理

数据

next字段可以不需要,客户端可以通过count字段计算出下一次请求的页码。
count字段只需要在获取第一页数据时返回。

逻辑要点

  • 下拉刷新:清空本地所有数据,加载第一页。
  • 上拉加载:使用当前页码加载数据。
  • 下拉刷新上拉加载加载网络数据成功后的共同逻辑:加载成功后通过count和获取到的数据总条数对比,如果还有数据,那么页码变量要加一。

界面

下拉刷新上拉加载有一个很好用的库推荐https://github.com/CoderMJLee/MJRefresh

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!