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

{
"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學習者快速成長!