gpt4 book ai didi

ios - ios 中 UITableview 中的分页

转载 作者:行者123 更新时间:2023-11-28 19:04:32 26 4
gpt4 key购买 nike

我的应用程序中有一个表格 View ,我正在向其中加载不同类型的单元格。我需要将页码作为一个、两个等传递给服务,并在第一页结束时加载它。对于我加载的第一个,计数是 10,之后当滚动结束时我需要加载下一个。我正在使用 Rest 客户端 Web 服务。这是我的 json 网络服务。

{
"userId":2,
"encryptPassword":"50ec0d1b0559dbba51a58bed38aabf7bc6066641",
"pagination":{
"lastId":0,
"resultsPerPage":10
},
"status_id":1,
"request_type_id":2,
"isAgent":false,
"searchKey":""
}

最佳答案

好吧,假设您正在 ping 服务器以获取前 10 个数据并将其显示到 tableview 现在您必须做的事情。

  • 采用全局 int 变量,如 int lastLoadedId=0;
  • 当您解析数据时,只需将最后加载的 ID 存储在 lastLoadedId 变量中即可跟踪您现在的位置。
  • 实现 -(void)scrollViewDidScroll: (UIScrollView*)scrollView 委托(delegate)方法以了解您位于底部并且需要新的下一个数据集。

-

-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
float scrollViewHeight = scrollView.frame.size.height;
float scrollContentSizeHeight = scrollView.contentSize.height;
float scrollOffset = scrollView.contentOffset.y;

if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
{
// you are in the end ping server with lastLoadedId for new data
}
}

-

  • 获取新数据集后,只需将它们附加到 tableview
  • 的底部即可

关于ios - ios 中 UITableview 中的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com